-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathblob.asm
163 lines (134 loc) · 4.74 KB
/
blob.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
; ===========================================================================
; Copyright (C) 2011-2018 by flamewing
;
; Permission to use, copy, modify, and/or distribute this software for any
; purpose with or without fee is hereby granted.
;
; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
; OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
; ===========================================================================
CPU 68000
supmode on ; We don't need warnings about privileged instructions
listing purecode ; Want listing file, but only the final code in expanded macros
paddingSoFar set 0
; 128 = 80h = z80, 32988 = 80DCh = z80unDoC
notZ80 function cpu,(cpu<>128)&&(cpu<>32988)
; define the even pseudo-instruction
even macro
if notZ80(MOMCPU)
if (*)&1
paddingSoFar set paddingSoFar+1
dc.b 0 ;ds.b 1
endif
else
if ($)&1
db 0
endif
endif
endm
; makes a VDP address difference
vdpCommDelta function addr,((addr&$3FFF)<<16)|((addr&$C000)>>14)
; makes a VDP command
vdpComm function addr,type,rwd,(((type&rwd)&3)<<30)|((addr&$3FFF)<<16)|(((type&rwd)&$FC)<<2)|((addr&$C000)>>14)
; values for the type argument
VRAM = %100001
CRAM = %101011
VSRAM = %100101
; values for the rwd argument
READ = %001100
WRITE = %000111
DMA = %100111
; tells the VDP to copy a region of 68k memory to VRAM or CRAM or VSRAM
dma68kToVDP macro source,dest,length,type
lea (VDP_control_port).l,a5
move.l #(($9400|((((length)>>1)&$FF00)>>8))<<16)|($9300|(((length)>>1)&$FF)),(a5)
if source>=0
lea source(pc),a1
move.l a1,d1
move.w #$9500,d0 ; command to specify source address & $0001FE
lsr.l #1,d1
move.b d1,d0
move.w d0,(a5) ; Send to VDP
move.w #$9600,d0 ; command to specify source address & $01FE00
lsr.w #8,d1
move.b d1,d0
move.w d0,(a5) ; Send to VDP
move.w #$9700,d0 ; command to specify source address & $FE0000
swap d1
move.b d1,d0
move.w d0,(a5) ; Send to VDP
else
move.l #(($9600|((((source)>>1)&$FF00)>>8))<<16)|($9500|(((source)>>1)&$FF)),(a5)
move.w #$9700|(((((source)>>1)&$FF0000)>>16)&$7F),(a5)
endif
move.w #((vdpComm(dest,type,DMA)>>16)&$FFFF),(a5)
move.w #(vdpComm(dest,type,DMA)&$FFFF),(a5)
endm
; tells the VDP to fill a region of VRAM with a certain byte
dmaFillVRAM macro byte,addr,length
lea (VDP_control_port).l,a5
move.w #$8F01,(a5) ; VRAM pointer increment: $0001
move.l #(($9400|((((length)-1)&$FF00)>>8))<<16)|($9300|(((length)-1)&$FF)),(a5) ; DMA length ...
move.w #$9780,(a5) ; VRAM fill
move.l #$40000080|(((addr)&$3FFF)<<16)|(((addr)&$C000)>>14),(a5) ; Start at ...
move.w #(byte)<<8,(VDP_data_port).l ; Fill with byte
.loop: move.w (a5),d1
btst #1,d1
bne.s .loop ; busy loop until the VDP is finished filling...
move.w #$8F02,(a5) ; VRAM pointer increment: $0002
endm
; calculates initial loop counter value for a dbf loop
; that writes n bytes total at 4 bytes per iteration
bytesToLcnt function n,n>>2-1
; tells the Z80 to stop, and waits for it to finish stopping (acquire bus)
stopZ80 macro
move.w #$100,(Z80_Bus_Request).l ; stop the Z80
.loop: btst #0,(Z80_Bus_Request).l
bne.s .loop ; loop until it says it's stopped
endm
; tells the Z80 to start again
startZ80 macro
move.w #0,(Z80_Bus_Request).l ; start the Z80
endm
; A few constants
palette_line_0 = (0<<13)
palette_line_1 = (1<<13)
palette_line_2 = (2<<13)
palette_line_3 = (3<<13)
tile_mask = $07FF
ramaddr function x,-(-x)&$FFFFFFFF
; Remapped RAM locations
Chunk_Table = ramaddr($FFFF0000)
System_Stack = ramaddr($FFFFFE00)
VDP_data_port = $C00000 ; (8=r/w, 16=r/w)
VDP_control_port = $C00004 ; (8=r/w, 16=r/w)
Z80_Bus_Request = $A11100
Z80_Reset = $A11200
; VRAM constants
ArtTile_VRAM_Start = $0000
; simplifying macros and functions
; macros to convert from tile index to art tiles, block mapping or VRAM address.
make_art_tile function addr,pal,pri,((pri&1)<<15)|((pal&3)<<13)|(addr&tile_mask)
tiles_to_bytes function addr,((addr&$7FF)<<5)
; macro to declare an offset table
offsetTable macro {INTLABEL}
current_offset_table := __LABEL__
__LABEL__ label *
endm
; macro to declare an entry in an offset table
offsetTableEntry macro ptr
dc.ATTRIBUTE ptr-current_offset_table
endm
ROMEndLoc = $1A4
debugger_blob = 1
; Remapped function names
KosDec:
dc.w $4EF9, $0BAD, $F00D
EniDec:
dc.w $4EF9, $DEAD, $BEEF
include "Debugger.asm"