Screen 4 pattern test not working (BASIC)

By kanageddaamen

Rookie (25)

kanageddaamen's picture

01-04-2018, 19:45

Hello all,

I wanted to just get a basic pattern test set up to do some testing of horizontal scroll functionality, so I tried creating a single pattern in screen 4 and populate the top 1/3 of the screen with it. Unfortunately, all I am seeing is the top 1/3rd of the screen is green, instead of alternating rows of red and green as I am aiming for. Here is my BASIC code

10 SCREEN 4
20 ' Set Color 0 to black
21 VDP(17)=0
22 OUT &H9A,0
23 OUT &H9A,0
24 ' Set Color 1 to red
25 VDP(17)=1
26 OUT &H9A,&B01110000
27 OUT &H9A,0
28 ' Set Color 2 to green
29 VDP(17)=2
30 OUT &H9A,0
31 OUT &H9A,&B00000111
40 ' Generate Pattern
41 VDP(15)=0
42 OUT &H99,0
43 OUT &H99,&B01000000
44 FOR I=1 TO 8
45 OUT &H98,&B10101010
46 NEXT
50 ' Set patterns for screen
51 VDP(15)=0
52 OUT &H99,0
53 OUT &H99,&B01011000
54 FOR I = 1 to 256
55 OUT &H98,0
56 NEXT
60 ' Set colors for patterns
61 VDP(15)=0
62 OUT &H99,0
63 OUT &H99,&B01100000
64 FOR I = 1 to 8
65 OUT &H98,&B00010010
66 NEXT
1000 IF NOT STRING(0) THEN 1000

Any insight would be greatly appreciated.

Login or register to post comments

By NYYRIKKI

Enlighted (5400)

NYYRIKKI's picture

02-04-2018, 11:25

Your code is fine in theory (if we don't calculate the miss spelled STRIG) and I was able to see it working fine even on emulated MSX. I think your problem is that BASIC is just not meant to be used like this... I'm sure you know that there are commands like COLOR= and VPOKE that you can use. I think the thing that is now ruining your life is interrupt routine... When interrupt happens it reads port &H99 and if that happens for example between lines 62 and 63 is messes up your address setup. You can get around the problem by using XBASIC and inline ML to disable the interrupts ( '#I 243) but I would say it is better idea to jump right in to assembly... You don't need to change more than few details and you are there already.

By zett

Hero (584)

zett's picture

02-04-2018, 12:48

sc4 is in basic standaard a emulated graphics mode. so not tile mode. there is a way to make it so like sc 1.5.
i use for it screen 1 editor. it outputs a .bin file you bload and it sets your tiles and mode to sc 1.5

By Grauw

Ascended (8516)

Grauw's picture

02-04-2018, 13:25

NYYRIKKI wrote:

…there are commands like COLOR= and VPOKE that you can use. I think the thing that is now ruining your life is interrupt routine... When interrupt happens it reads port &H99 and if that happens [...] it messes up your address setup.

Also a word of warning if you have an ISR which sets VDP registers (the BIOS ISR doesn’t):

When accessing the palette, the first byte written to 9AH (red/green) is latched in the same internal register as when you set a register or VRAM address using 99H. So if you access 99H between writing the red/green value and writing the blue value (e.g. because an ISR occurs), the latch is overwritten and the palette is corrupted.

I found this out yesterday, a rare corruption issue, had to wrap it in di/ei to fix it Crying.

By kanageddaamen

Rookie (25)

kanageddaamen's picture

02-04-2018, 15:00

Ahhh, thanks for the help. I was hoping to just throw some quick BASIC together but I will just jump into ASM

By Grauw

Ascended (8516)

Grauw's picture

02-04-2018, 15:18

Well, you could use VDP(), VPOKE and COLOR= to achieve the same…

10 SCREEN 4 : DEFINT A-Z
20 ' Set Color 0 to black
21 COLOR=(0,0,0,0)
24 ' Set Color 1 to red
25 COLOR=(1,7,0,0)
28 ' Set Color 2 to green
29 COLOR=(2,0,0,6)
40 ' Generate Pattern
44 FOR I=0 TO 7
45 VPOKE I,&B10101010
46 NEXT
50 ' Set patterns for screen
54 FOR I = 0 to 255
55 VPOKE &H1800 + I,0
56 NEXT
60 ' Set colors for patterns
64 FOR I = 0 to 7
65 VPOKE &H2000 + I,&B00010010
66 NEXT
1000 IF NOT STRIG(0) THEN 1000

Also you can use BASE() to determine the vpoke address offset:

45 VPOKE BASE(22) + I,&B10101010
55 VPOKE BASE(20) + I,0
65 VPOKE BASE(21) + I,&B00010010