Skip to content

Commit 1781770

Browse files
committed
Optimize PMGRAPHICS a little, 4 bytes less.
1 parent 64d60eb commit 1781770

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

src/interp/pmgraphics.asm

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,42 +36,44 @@
3636
.segment "RUNTIME"
3737

3838
.proc EXE_PMGRAPHICS
39+
and #3 ; only two modes
3940
tax ; Disable if 0
4041
beq disable_pm
41-
and #1 ; only two modes
42-
tax
43-
; TODO: copied from AtBasic - optimize
44-
ldy pmgmode_tab,x ; Get mode
45-
lda mask_tab,x ; Get address mask
42+
43+
; Note: if A == 3, mask_tab will point to a 0,
44+
; so we will have a MEMORY ERROR.
45+
;
46+
ldy #3 ; Load valir for GRACTL
47+
lda mask_tab-1,x ; Get address mask
4648
and MEMTOP+1
4749
clc ; Subtract to get P/M base
48-
adc mask_tab,x
50+
adc mask_tab-1,x
4951
cmp array_ptr+1
5052
bcs mem_ok
5153
jmp err_nomem
5254

5355
disable_pm:
54-
txa ; Set A,X and Y to 0, used to write register values
55-
tay
56-
clc
56+
tay ; Store 0 in GRACTL
5757
mem_ok:
5858
sta pmgbase
5959
sta PMBASE
60-
sty pmgmode
6160

6261
lda SDMCTL
6362
and #$e3
64-
bcc skip_pmenable
6563
ora pmg_dmactl_tab,x
66-
ldy #3
67-
skip_pmenable:
6864
sta SDMCTL
6965
sty GRACTL
7066
tya ; bit 1 already set
7167
ora GPRIOR
7268
and #$c1
7369
sta GPRIOR
7470

71+
; Note: when X = 0, mode is written an invalid
72+
; value, but it won't matter as MODE is not used
73+
; when P/M graphics are disabled.
74+
ldy pmgmode_tab-1,x
75+
sty pmgmode
76+
7577
; Reset GTIA registers (P/M position, sizes and hit)
7678
ldy #17
7779
lda #0
@@ -87,11 +89,11 @@ pmgbase:
8789
pmgmode:
8890
.byte 0
8991
mask_tab:
90-
.byte $fc,$f8
92+
.byte $f8,$fc
9193
pmg_dmactl_tab:
92-
.byte $0c,$1c
94+
.byte $00,$1c,$0c
9395
pmgmode_tab:
94-
.byte $40,$80
96+
.byte $80,$40
9597

9698
PMGBASE = pmgbase
9799
PMGMODE = pmgmode

0 commit comments

Comments
 (0)