Skip to content

Commit 082c9f4

Browse files
committed
Adds P/M graphics support: PMGRAPHICS (PM.) and PMADR().
1 parent 40b5f74 commit 082c9f4

File tree

6 files changed

+119
-22
lines changed

6 files changed

+119
-22
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ COMMON_AS_SRC=\
144144
src/interp/pause.asm\
145145
src/interp/peek.asm\
146146
src/interp/plot.asm\
147+
src/interp/pmgraphics.asm\
147148
src/interp/poke.asm\
148149
src/interp/print_eol.asm\
149150
src/interp/print_str.asm\

samples/int/pmtest.bas

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
' P/M test program
2-
RAMTOP = $6A : SDMCTL = $22F : PCOLR0 = $2C0
3-
HPOSP0 = $D000 : GRACTL = $D01D : PMBASE = $D407
4-
' Reserve memory at TOP
5-
MemTop = Peek(RAMTOP) - 4
6-
P0Mem = $100 * MemTop + $200
7-
oldPos = P0Mem
8-
poke RAMTOP, MemTop
9-
10-
' Activate and configure P/M data
11-
graphics 0
12-
mset P0Mem, 128, 0 ' Clears Memory
13-
poke PCOLR0, $1F
14-
poke SDMCTL, Peek(SDMCTL) ! 8
15-
poke PMBASE, MemTop
16-
poke GRACTL, 2
2+
HPOSP0 = $D000
3+
4+
graphics 0 ' Setups graphics mode
5+
pmgraphics 2 ' And P/M mode
6+
P0Mem = pmadr(0) ' Get player 0 address
7+
oldPos = P0Mem ' and into "old position"
8+
9+
mset P0Mem, 128, 0 ' Clears P/M 0 Memory
10+
setcolor -4, 1, 15
1711

1812
' P/M data and blank (to clear P/M)
1913
DATA PMdata() byte = $38,$44,$54,$44,$38
@@ -37,10 +31,6 @@ repeat
3731
exec MovePm ' Move P/M Graphics
3832
until Key()
3933

40-
' Restore RAMTOP and SDMCTL
41-
poke GRACTL, 0
42-
poke SDMCTL, Peek(SDMCTL) & 247
43-
poke RAMTOP, MemTop + 4
4434
graphics 0
4535

4636
END

src/basic.syn

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ TOKENS {
4646
TOK_VAR_STORE, TOK_SADDR, TOK_INCVAR, TOK_DECVAR
4747
# Graphic support statements
4848
TOK_GRAPHICS, TOK_PLOT, TOK_DRAWTO
49+
# P/M statements
50+
TOK_PMGRAPHICS
4951
# Print statements
5052
TOK_PRINT_STR, TOK_PRINT_TAB, TOK_PRINT_EOL
5153
# I/O
@@ -197,6 +199,7 @@ T_EXPR: integer constant, variable or function
197199
"PTRIG" emit TOK_NUM word PTRIG0 emit TOK_PUSH_BYTE emit 7 RD_PORT
198200
"STICK" emit TOK_NUM word STICK0 emit TOK_PUSH_BYTE emit 3 RD_PORT
199201
"STRIG" emit TOK_NUM word STRIG0 emit TOK_PUSH_BYTE emit 3 RD_PORT
202+
"PMADR" PAR_EXPR emit TOK_PUSH_BYTE emit 4 emit TOK_ADD emit TOK_PUSH_NUM word PMGMODE emit TOK_PEEK emit TOK_USHL emit TOK_MUL emit TOK_PUSH_NUM word PMGBASE emit TOK_PEEK emit TOK_SHL8 emit TOK_ADD
200203
#@if FASTBASIC_FP
201204
"INT" FP_PAR_EXPR emit TOK_FP_INT
202205
#@endif FASTBASIC_FP
@@ -574,7 +577,7 @@ PARSE_LINE_COMMAND:
574577
"ELIf" emit TOK_JUMP E_ELIF FORCE_BOOL_EXPR emit TOK_CJUMP emit LT_IF E_PUSH_LT
575578
"ENDif" E_POP_IF
576579
"EXit" emit TOK_JUMP E_EXIT_LOOP
577-
"Graphics" emit TOK_BYTE emit 6 emit TOK_CLOSE EXPR emit TOK_GRAPHICS
580+
"Graphics" emit TOK_0 emit TOK_PMGRAPHICS emit TOK_BYTE emit 6 emit TOK_CLOSE EXPR emit TOK_GRAPHICS
578581
"Color" emit TOK_BYTE_SADDR emit COLOR EXPR emit TOK_POKE
579582
"FColor" emit TOK_NUM word FILDAT emit TOK_SADDR EXPR emit TOK_POKE
580583
"POSition" POSITION
@@ -601,6 +604,7 @@ PARSE_LINE_COMMAND:
601604
"DEG" emit TOK_BYTE_SADDR emit DEGFLAG emit TOK_1 emit TOK_POKE
602605
"RAd" emit TOK_BYTE_SADDR emit DEGFLAG emit TOK_0 emit TOK_POKE
603606
#@endif FASTBASIC_FP
607+
"PMGraphics" EXPR emit TOK_PMGRAPHICS
604608

605609
PARSE_LINE_ASSIGN:
606610
VAR_WORD_SAVE "=" EXPR emit TOK_VAR_STORE E_POP_VAR

src/clearmem.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
; Clear Memory
2828
; ------------
2929

30-
.export clear_data, alloc_array, mem_set
30+
.export clear_data, alloc_array, mem_set, err_nomem
3131

3232
.import putc, EXE_END
3333
.importzp mem_end, var_page, tmp1, tmp2, array_ptr, var_count

src/interp/pmgraphics.asm

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
;
2+
; FastBasic - Fast basic interpreter for the Atari 8-bit computers
3+
; Copyright (C) 2017-2019 Daniel Serpell
4+
;
5+
; This program is free software; you can redistribute it and/or modify
6+
; it under the terms of the GNU General Public License as published by
7+
; the Free Software Foundation, either version 2 of the License, or
8+
; (at your option) any later version.
9+
;
10+
; This program is distributed in the hope that it will be useful,
11+
; but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
; GNU General Public License for more details.
14+
;
15+
; You should have received a copy of the GNU General Public License along
16+
; with this program. If not, see <http://www.gnu.org/licenses/>
17+
;
18+
; In addition to the permissions in the GNU General Public License, the
19+
; authors give you unlimited permission to link the compiled version of
20+
; this file into combinations with other programs, and to distribute those
21+
; combinations without any restriction coming from the use of this file.
22+
; (The General Public License restrictions do apply in other respects; for
23+
; example, they cover modification of the file, and distribution when not
24+
; linked into a combine executable.)
25+
26+
27+
; PMGRAPHICS: P/M graphic setup
28+
; -----------------------------
29+
30+
.export PMGBASE, PMGMODE
31+
.import err_nomem
32+
.importzp array_ptr, next_instruction
33+
34+
.include "atari.inc"
35+
36+
.segment "RUNTIME"
37+
38+
.proc EXE_PMGRAPHICS
39+
tax ; Disable if 0
40+
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
46+
and MEMTOP+1
47+
clc ; Subtract to get P/M base
48+
adc mask_tab,x
49+
cmp array_ptr+1
50+
bcs mem_ok
51+
jmp err_nomem
52+
53+
disable_pm:
54+
txa ; Set A,X and Y to 0, used to write register values
55+
tay
56+
clc
57+
mem_ok:
58+
sta pmgbase
59+
sta PMBASE
60+
sty pmgmode
61+
62+
lda SDMCTL
63+
and #$e3
64+
bcc skip_pmenable
65+
ora pmg_dmactl_tab,x
66+
ldy #3
67+
skip_pmenable:
68+
sta SDMCTL
69+
sty GRACTL
70+
tya ; bit 1 already set
71+
ora GPRIOR
72+
and #$c1
73+
sta GPRIOR
74+
75+
; Reset GTIA registers (P/M position, sizes and hit)
76+
ldy #17
77+
lda #0
78+
: sta HPOSP0, y
79+
dey
80+
bpl :-
81+
82+
jmp next_instruction
83+
.endproc
84+
85+
pmgbase:
86+
.byte 0
87+
pmgmode:
88+
.byte 0
89+
mask_tab:
90+
.byte $fc,$f8
91+
pmg_dmactl_tab:
92+
.byte $0c,$1c
93+
pmgmode_tab:
94+
.byte $40,$80
95+
96+
PMGBASE = pmgbase
97+
PMGMODE = pmgmode
98+
99+
.include "../deftok.inc"
100+
deftoken "PMGRAPHICS"
101+
102+
; vi:syntax=asm_ca65

src/parse.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
.import putc
4141
; From interpreter.asm
4242
.importzp DEGFLAG, DEGFLAG_DEG, DEGFLAG_RAD
43-
.import EXE_END, saved_cpu_stack
43+
.import EXE_END, saved_cpu_stack, PMGMODE, PMGBASE
4444
; From errors.asm
4545
.import error_msg_list
4646
.importzp ERR_PARSE, ERR_NO_ELOOP, ERR_LABEL, ERR_TOO_LONG

0 commit comments

Comments
 (0)