Skip to content

Commit a5222a5

Browse files
committed
A5200: implement PLOT in graphic modes.
Modes 7 to 11 and 15 are supported.
1 parent 17e0f76 commit a5222a5

3 files changed

Lines changed: 124 additions & 3 deletions

File tree

src/interp/a5200/drawto.asm

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,130 @@
2727
; Line drawing
2828
; ------------
2929

30+
.importzp DINDEX, COLOR, IOERROR, COLCRS, ROWCRS, tmp4
31+
.importzp SAVMSC, next_instruction, tmp1
32+
.import gr_mask_p, gr_shift_x, gr_mask_s, EXE_PUT
33+
34+
.zeropage
35+
mask: .res 1
36+
color_s:.res 1
37+
38+
3039
; TODO: implement line drawing for all graphic modes
40+
.segment "RUNTIME"
41+
42+
.proc EXE_PLOT ; Plot a point into current position
43+
; Compatibility: for text modes, this is the same as "PUT":
44+
bit DINDEX
45+
bpl do_plot
46+
lda COLOR
47+
jmp EXE_PUT
48+
do_plot:
49+
jsr get_addr
50+
lda mask
51+
eor #$FF
52+
and (tmp4), y
53+
ora color_s
54+
sta (tmp4), y
55+
jmp next_instruction
56+
.endproc
3157

3258
.proc EXE_DRAWTO ; Draw line from last position to current
59+
jmp next_instruction
60+
.endproc
61+
62+
63+
.proc get_addr
64+
lda ROWCRS
65+
66+
; Multiply A by 4, overflowing to X
67+
ldx #0
68+
asl
69+
bcc L1
70+
ldx #2
71+
L1: asl
72+
bcc L2
73+
inx
74+
clc
75+
76+
; Add to original, multiply by 5
77+
L2: adc ROWCRS
78+
bcc :+
79+
inx
80+
:
81+
; And shift 3 times, multiply by 40:
82+
stx tmp4+1
83+
asl
84+
rol tmp4+1
85+
asl
86+
rol tmp4+1
87+
asl
88+
rol tmp4+1
89+
90+
; Add to screen address
91+
adc SAVMSC
92+
sta tmp4
93+
lda tmp4+1
94+
adc SAVMSC+1
95+
sta tmp4+1
96+
cmp #$40 ; Compare with top of ram
97+
bcs ret_error
98+
99+
; Get mask and shift amounts
100+
ldx DINDEX
101+
lda gr_mask_p, x
102+
sta mask
103+
104+
ldy gr_shift_x, x
105+
106+
; First shift is 16 bits
107+
lda COLCRS+1
108+
lsr
109+
lda COLCRS
110+
sta tmp1
111+
lda #192
112+
; Next shifts are 8 bits
113+
shift: ror tmp1 ; Shift column position
114+
ror ; Shift bit position
115+
dey
116+
bne shift
117+
; Here A = bit position * 32, shift 4 more times:
118+
rol
119+
rol
120+
rol
121+
rol
122+
and #7
123+
eor #7
124+
tax
125+
126+
; Generate bit pattern and mask
127+
lda COLOR
128+
and mask
129+
130+
dex
131+
bmi ok_mask
132+
rol_mask:
133+
asl
134+
asl mask
135+
dex
136+
bpl rol_mask
137+
ok_mask:
138+
sta color_s
139+
140+
ldy tmp1
33141
rts
34142
.endproc
35143

144+
; Return from calling code with error
145+
ret_error:
146+
pla
147+
pla
148+
lda #18
149+
sta IOERROR
150+
jmp next_instruction
151+
36152
.include "deftok.inc"
37153
deftoken "DRAWTO"
154+
deftoken "PLOT"
38155

39156
; vi:syntax=asm_ca65

src/interp/a5200/graphics.asm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
; Atari 5200 GRAPHICS statement
2828
; -----------------------------
2929

30-
.export set_grmode
30+
.export set_grmode, gr_mask_p, gr_shift_x
3131
.importzp tmp1, tmp2, next_instruction
3232
.importzp DINDEX, COLCRS, ROWCRS, SAVMSC, COLOR
3333
.import mem_set_0, MEMTOP, GPRIOR
@@ -209,6 +209,10 @@ dl_adr_l: .lobytes $3098, $2126, $2126, $2126, $3E00, $3EF0, $3C20, $3E00
209209
dl_adr_h: .hibytes $3098, $2126, $2126, $2126, $3E00, $3EF0, $3C20, $3E00
210210
rows: .byte 96, 192, 192, 192, 24, 12, 24, 12
211211

212+
; 2bpp 1bpp 4bpp 2bpp
213+
gr_mask_p: .byte 3, 1, 15, 3
214+
gr_shift_x: .byte 2, 3, 1, 2
215+
212216
.include "deftok.inc"
213217
deftoken "GRAPHICS"
214218

src/syntax/gr-a5200.syn

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# Graphic support statements for the Atari 5200
2020

2121
TOKENS {
22-
TOK_GRAPHICS, TOK_DRAWTO
22+
TOK_GRAPHICS, TOK_DRAWTO, TOK_PLOT
2323
}
2424

2525
SYMBOLS {
@@ -30,7 +30,7 @@ SYMBOLS {
3030
STATEMENT:
3131
"Graphics" emit { TOK_0, TOK_PMGRAPHICS } EXPR emit TOK_GRAPHICS
3232
"Color" EXPR emit { TOK_BYTE_POKE, COLOR }
33-
"PLot" POSITION emit { TOK_BYTE_PEEK, COLOR, TOK_PUT }
33+
"PLot" POSITION emit { TOK_PLOT }
3434
"DRawto" POSITION emit { TOK_DRAWTO }
3535
"SEtcolor" EXPR emit { TOK_PUSH_NUM, &COLOR0, TOK_ADD, TOK_SADDR } EXPR_AB emit TOK_POKE
3636

0 commit comments

Comments
 (0)