This lua stuff is really cool.

I wanted to see if it could write to the TMS9918 on the arcade board and I was able to write to the VRAM, but I couldn't find a way to access the TMS9918 registers programmatically.

I think that the TMS9918 have to be initialized with a real program, because there are side effects from the code that sets the registers. Once it's initialized, then I can just write stuff to the VRAM space and it displays.

Wow, this is so much faster to run than my Applesoft programs. The effects are seen virtually instantaneously.

Now if I just had a way to do an emu.frameadvance() (which doesn't work) or some kind of way to do a delay like wait for vblank.


[Linked Image from i.imgur.com]



A very short program to initialize the TMS 9918 registers.

Code
1  DEF  FN LO(X) = ((X / 256) -  INT (X / 256)) * 256: DEF  FN HI(X) =  INT (X / 256)

4  GOTO 100
5  PRINT "REG WRITE: SLOT=";S;" VALUE=";W0;" REG=";W1
6 SB = 49280:S0 = SB + 16 * S:S1 = S0 + 1
7 IP = 16384
8  POKE IP,160 + 13: POKE IP + 1, FN LO(S1): POKE IP + 2, FN HI(S1): REM LDA $C0C1
9 IP = IP + 3: POKE IP,160 + 9: POKE IP + 1,W0:IP = IP + 2: REM LDA #$W0
10  POKE IP,128 + 13: POKE IP + 1, FN LO(S1): POKE IP + 2, FN HI(S1):IP = IP + 3: REM STA $C0C1
11 IP = IP + 0: POKE IP,160 + 9: POKE IP + 1,W1:IP = IP + 2: REM LDA #$W1
13 IP = IP + 0: POKE IP,128 + 13: POKE IP + 1, FN LO(S1): POKE IP + 2, FN HI(S1):IP = IP + 3: REM STA $C0C1
14  POKE IP,6 * 16:IP = IP + 1: REM  RTS
15  CALL 16384
16  RETURN 

100 S = 4:W0 = 2:W1 = 128 + 0: GOSUB 5
101 S = 4:W0 = 193:W1 = 128 + 1: GOSUB 5
102 S = 4:W0 = 14:W1 = 128 + 2: GOSUB 5
103 S = 4:W0 = 255:W1 = 128 + 3: GOSUB 5
104 S = 4:W0 = 3:W1 = 128 + 4: GOSUB 5
105 S = 4:W0 = 118:W1 = 128 + 5: GOSUB 5
106 S = 4:W0 = 3:W1 = 128 + 6: GOSUB 5
107 S = 4:W0 = 15:W1 = 128 + 7: GOSUB 5
108  END 

Then I can run this lua program with dofile("fontarray_tms.lua")


Code
tms= manager:machine().devices[":sl4:arcbd:arcbd_tms"]
mem = tms.spaces["vram"]

fontarray = {32, 0,0,0,0,0,0,0,0,
33, 24,60,60,24,24,0,24,0,
34, 108,108,0,0,0,0,0,0,
35, 108,108,254,108,254,108,108,0,
36, 24,62,96,60,6,124,24,0,
37, 0,198,204,24,48,102,198,0,
38, 56,108,104,118,220,204,118,0,
39, 24,24,48,0,0,0,0,0,
40, 12,24,48,48,48,24,12,0,
41, 48,24,12,12,12,24,48,0,
42, 0,102,60,255,60,102,0,0,
43, 0,24,24,126,24,24,0,0,
44, 0,0,0,0,0,24,24,48,
45, 0,0,0,126,0,0,0,0,
46, 0,0,0,0,0,24,24,0,
47, 3,6,12,24,48,96,192,0,
48, 60,102,110,126,118,102,60,0,
49, 24,56,24,24,24,24,126,0,
50, 60,102,6,28,48,102,126,0,
51, 60,102,6,28,6,102,60,0,
52, 28,60,108,204,254,12,30,0,
53, 126,96,124,6,6,102,60,0,
54, 28,48,96,124,102,102,60,0,
55, 126,102,6,12,24,24,24,0,
56, 60,102,102,60,102,102,60,0,
57, 60,102,102,62,6,12,56,0,
58, 0,24,24,0,0,24,24,0,
59, 0,24,24,0,0,24,24,48,
60, 12,24,48,96,48,24,12,0,
61, 0,0,126,0,0,126,0,0,
62, 48,24,12,6,12,24,48,0,
63, 60,102,6,12,24,0,24,0,
64, 124,198,222,222,222,192,120,0,
65, 24,60,60,102,126,195,195,0,
66, 252,102,102,124,102,102,252,0,
67, 60,102,192,192,192,102,60,0,
68, 248,108,102,102,102,108,248,0,
69, 254,102,96,120,96,102,254,0,
70, 254,102,96,120,96,96,240,0,
71, 60,102,192,206,198,102,62,0,
72, 102,102,102,126,102,102,102,0,
73, 126,24,24,24,24,24,126,0,
74, 14,6,6,6,102,102,60,0,
75, 230,102,108,120,108,102,230,0,
76, 240,96,96,96,98,102,254,0,
77, 130,198,238,254,214,198,198,0,
78, 198,230,246,222,206,198,198,0,
79, 56,108,198,198,198,108,56,0,
80, 252,102,102,124,96,96,240,0,
81, 56,108,198,198,198,108,60,6,
82, 252,102,102,124,108,102,227,0,
83, 60,102,112,56,14,102,60,0,
84, 126,90,24,24,24,24,60,0,
85, 102,102,102,102,102,102,62,0,
86, 195,195,102,102,60,60,24,0,
87, 198,198,198,214,254,238,198,0,
88, 195,102,60,24,60,102,195,0,
89, 195,195,102,60,24,24,60,0,
90, 254,198,140,24,50,102,254,0,
91, 60,48,48,48,48,48,60,0,
92, 192,96,48,24,12,6,3,0,
93, 60,12,12,12,12,12,60,0,
94, 16,56,108,198,0,0,0,0,
95, 0,0,0,0,0,0,0,254,
96, 24,24,12,0,0,0,0,0,
97, 0,0,60,6,30,102,59,0,
98, 224,96,108,118,102,102,60,0,
99, 0,0,60,102,96,102,60,0,
100, 14,6,54,110,102,102,59,0,
101, 0,0,60,102,126,96,60,0,
102, 28,54,48,120,48,48,120,0,
103, 0,0,59,102,102,60,198,124,
104, 224,96,108,118,102,102,230,0,
105, 24,0,56,24,24,24,60,0,
106, 6,0,6,6,6,6,102,60,
107, 224,96,102,108,120,108,230,0,
108, 56,24,24,24,24,24,60,0,
109, 0,0,102,119,107,99,99,0,
110, 0,0,124,102,102,102,102,0,
111, 0,0,60,102,102,102,60,0,
112, 0,0,220,102,102,124,96,240,
113, 0,0,61,102,102,62,6,7,
114, 0,0,236,118,102,96,240,0,
115, 0,0,62,96,60,6,124,0,
116, 16,48,124,48,48,52,24,0,
117, 0,0,204,204,204,204,118,0,
118, 0,0,204,204,204,120,48,0,
119, 0,0,198,214,214,108,108,0,
120, 0,0,99,54,28,54,99,0,
121, 0,0,102,102,102,60,24,112,
122, 0,0,126,76,24,50,126,0,
123, 14,24,24,112,24,24,14,0,
124, 24,24,24,24,24,24,24,0,
125, 112,24,24,14,24,24,112,0,
126, 114,156,0,0,0,0,0,0,
127, 0,0,0,0,0,0,0,0
}

-- pattern table at 0x0000

i=1
bytepos=0x0000+32*8
while(true) do
 if i>table.maxn(fontarray) then break; end;
  charnum = fontarray[i];
  i = i + 1;
  for j=1,8 do  mem:write_i8(bytepos,fontarray[i]); i = i + 1; bytepos = bytepos+1; end
end

-- name table at 0x3800

bytepos = 0x3800

for j=0,2 do
for i=0,255 do mem:write_i8(bytepos,i); bytepos = bytepos+1; end
end

-- color table at 0x2000

bytepos = 0x2000

for i=0,6143 do mem:write_i8(bytepos,15*16+4); bytepos = bytepos+1; end

-- use our font array for a sprite pattern table also

i=1
bytepos=0x1800+32*8
while(true) do
 if i>table.maxn(fontarray) then break; end;
  charnum = fontarray[i];
  i = i + 1;
  for j=1,8 do  mem:write_i8(bytepos,fontarray[i]); i = i + 1; bytepos = bytepos+1; end
end

function setsprite(sprite,x,y,pattern,color)
bytepos=0x3b00+sprite*4
if y>=0 then mem:write_i8(bytepos,y) end -- vertical first
if x>=0 then mem:write_i8(bytepos+1,x)  end
if pattern>=0 then mem:write_i8(bytepos+2,pattern) end
if color >=0 then mem:write_i8(bytepos+3,color) end
end


a = "MameTMS 99184 spriteper line max"

for i=0,string.len(a)-1 do
 setsprite(i,50+(i%4)*20,30+math.floor(i/4)*20,string.byte(a,i+1),(i*2+1)%16);
end

-- dofile("fontarray_tms.lua")