Skip to content

Commit 839111d

Browse files
committed
MEGA65 mode prg, MEGA65 fixes, still no audio :(
1 parent 44f9f85 commit 839111d

File tree

4 files changed

+121
-38
lines changed

4 files changed

+121
-38
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ CL65 = cl65
66
CL65OPT = -t none
77
VICE = x64
88
XEMU = xemu-xmega65
9-
M65 = m65
9+
M65 = mega65_etherload
1010
ALLDEP = Makefile test.dro ld.cfg
1111

1212
all: $(PRG) $(PRG65)
@@ -28,7 +28,7 @@ xemu: $(PRG65)
2828
$(XEMU) -prg $<
2929

3030
mega65: $(PRG65)
31-
$(M65) -F -4 -r $<
31+
$(M65) -r $<
3232

3333
clean:
3434
rm -f *.o *.prg

c64_play.a65

Lines changed: 119 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
; of an OPL3 chip. Currently only tested with Xemu emulation of MEGA65,
99
; which has some issues though.
1010
; ---------------------------------------------------------------------
11-
; VERSION: 1.2a
11+
; VERSION: 1.3a
1212
; ---------------------------------------------------------------------
13-
; (C)2011,2020-2021 LGB (Gábor Lénárt) [email protected], this program can be used
13+
; (C)2011,2020-2021,2024 LGB (Gábor Lénárt) [email protected], this program can be used
1414
; according to the GNU/GPL 2 or 3 (or later, if a new one is released) license.
1515
; License: http://www.gnu.org/licenses/gpl-2.0.html
1616
; License: http://www.gnu.org/licenses/gpl-3.0.html
@@ -71,11 +71,14 @@
7171
; ---------------------------------------------------------------------
7272

7373
.IFDEF MEGA65
74-
.SETCPU "4510"
75-
.MACRO SET_OPL_Z
76-
NOP
77-
STA (oplregs),Z
78-
.ENDMACRO
74+
.SETCPU "4510"
75+
.MACRO STAOPL_Z
76+
NOP
77+
STA (oplregs),Z
78+
.ENDMACRO
79+
D018_VALUE = 38 ; MEGA65
80+
.ELSE
81+
D018_VALUE = 23 ; C64
7982
.ENDIF
8083

8184

@@ -91,21 +94,24 @@ oplregs:.RES 4
9194

9295
screen_reg_addrs: .RES 512
9396

94-
;.SEGMENT "ZPSAVE" ; not used here so much
95-
;.SEGMENT "INIT"
96-
;.SEGMENT "ONCE"
97-
9897
.CODE
9998

99+
.IFDEF MEGA65
100+
.ORG $1FFF
101+
.ELSE
100102
.ORG $7FF
101-
103+
.ENDIF
102104

103105
; BASIC stub: do NOT place anything into the STARTUP segment
104106
; before the stub itself!
105107
;.SEGMENT "STARTUP"
106108
.WORD basic_loader
107109
basic_loader:
108-
.WORD @lastline,2012
110+
.WORD @lastline,2024
111+
.IFDEF MEGA65
112+
.WORD $02FE ; "BANK" BASIC10/65 token (double byte token!)
113+
.BYTE "0:"
114+
.ENDIF
109115
.BYTE $9E ; "SYS" basic token
110116
.BYTE $30+.LOBYTE(main/10000)
111117
.BYTE $30+.LOBYTE((main .MOD 10000)/1000)
@@ -141,10 +147,16 @@ cmd_long_delay = song + 24
141147
codemap_len = song + 25
142148
codemap = song + 26
143149

150+
.IFNDEF MEGA65
144151
SFX_YM_SELECT_REGISTER = $DF40
145152
SFX_YM_DATA_REGISTER = $DF50
153+
.ENDIF
146154

155+
.IFDEF MEGA65
156+
SCREEN_ADDRESS = $0800
157+
.ELSE
147158
SCREEN_ADDRESS = $0400
159+
.ENDIF
148160
COLOR_ADDRESS = $D800
149161
COLOR_RAM_OFFSET = COLOR_ADDRESS - SCREEN_ADDRESS
150162
REGDUMP_START_POS = SCREEN_ADDRESS + 41
@@ -182,7 +194,7 @@ header:
182194
.ELSE
183195
.BYTE "M65"
184196
.ENDIF
185-
.BYTE " DRO player v1.2a by LGB [email protected] "
197+
.BYTE " DRO player v1.3a by LGB [email protected] "
186198
header_size = * - header
187199

188200
song:
@@ -241,20 +253,41 @@ show_hex_byte: ; A=byte, ZP: screen address base, Y = offset (from ZP)
241253
reset_sfx:
242254
.IFDEF MEGA65
243255
; Setting up memory pointer
244-
; MEGA65 I/O address: FE000xx -> 0F E0 00 xx
256+
; 7FFDF00 -> 07 FF DF 00
245257
LDA #$00
246258
STA oplregs
259+
LDA #$DF
247260
STA oplregs+1
248-
LDA #$E0
261+
LDA #$FF
249262
STA oplregs+2
250-
LDA #$0F
263+
LDA #$07
251264
STA oplregs+3
252265
; Write zeroes for all registers:
253266
LDA #0
254-
LDZ #0
255-
: SET_OPL_Z
256-
INZ
257-
STZ $D020
267+
LDX #0
268+
: LDZ #$40
269+
TXA
270+
STAOPL_Z
271+
JSR waitopl
272+
LDZ #$50
273+
LDA #$00
274+
STAOPL_Z
275+
JSR waitopl
276+
INX
277+
BNE :-
278+
; MEGA65 specific sequence which seems to be needed to produce any sound. Thanks, btoschi!
279+
; ($C0...$C8, 9 registers)
280+
LDX #$C0
281+
: LDZ #$40
282+
TXA
283+
STAOPL_Z
284+
JSR waitopl
285+
LDZ #$50
286+
LDA #$F0
287+
STAOPL_Z
288+
JSR waitopl
289+
INX
290+
CPX #$C9
258291
BNE :-
259292
RTS
260293
.ELSE
@@ -277,20 +310,18 @@ reset_sfx:
277310
.ENDIF
278311

279312

313+
.IFDEF MEGA65
314+
waitopl:
315+
PHX
316+
LDX #$98
317+
: DEX
318+
BNE :-
319+
PLX
320+
RTS
321+
.ENDIF
280322

281323

282324
main:
283-
.IFDEF MEGA65
284-
; Turn off "force fast" mode of MEGA65 just in case (player uses software timing ...)
285-
LDA #64
286-
STA 0
287-
; Set MEGA65 I/O mode: not needed too much by this player yet, but maybe in the future
288-
; CPU persona of MEGA65 defaults to 6510 (thus excluding the linear addressing we need!) in normal C64 VIC I/O mode ...
289-
LDA #$47
290-
STA $D02F
291-
LDA #$53
292-
STA $D02F
293-
.ENDIF
294325
; Disable interrupts (timing can be "perfect")
295326
; Note: later, the stuff should be rewritten to be
296327
; IRQ based player ...
@@ -303,8 +334,28 @@ main:
303334
; This is only a quick TEST, do not except advanced
304335
; features now.
305336
SEI
337+
.IFDEF MEGA65
338+
LDA #0
339+
TAZ
340+
TAX
341+
TAY
342+
MAP
343+
; Turn off "force fast" mode of MEGA65 just in case (player uses software timing ...)
344+
LDA #64
345+
STA 0
346+
; Set MEGA65 I/O mode: not needed too much by this player yet, but maybe in the future
347+
; CPU persona of MEGA65 [may?] defaults to 6510 (thus excluding the linear addressing we need!) in normal C64 VIC I/O mode ...
348+
LDA #$47
349+
STA $D02F
350+
LDA #$53
351+
STA $D02F
352+
; ...
353+
LDA #0
354+
STA $D030
355+
STA $D031
356+
.ENDIF
306357
; Select lower-case character set
307-
LDA #23
358+
LDA #D018_VALUE
308359
STA $D018
309360
; "Nice" black screen, also clear it, with filling the color RAM as well
310361
LDX #0
@@ -502,7 +553,14 @@ main:
502553
; However, at this point we have enough instructions between writes,
503554
; so I simply don't need any additional delay (I hope so, at least)
504555
.IFDEF MEGA65
505-
TAZ ; OPL register number only causes to set Z register on MEGA65
556+
; Check if register is not forbidden to write
557+
; THIS IS MY LAST ATTEMPT to try to make it work with MEGA65 with disallowing
558+
; DRO to modify certain registers ...
559+
TAX
560+
LDY skip_mega_reg_tab,X
561+
BNE @skipmegareg
562+
LDZ #$40
563+
STAOPL_Z
506564
.ELSE
507565
STA SFX_YM_SELECT_REGISTER
508566
.ENDIF
@@ -511,10 +569,12 @@ main:
511569
NOP
512570
LDA ZP+1
513571
.IFDEF MEGA65
514-
SET_OPL_Z ; use MEGA65 linear addressing, Z register is already set
572+
LDZ #$50
573+
STAOPL_Z
515574
.ELSE
516575
STA SFX_YM_DATA_REGISTER
517576
.ENDIF
577+
@skipmegareg:
518578
; show it!
519579
JSR show_reg
520580
; check looping
@@ -576,4 +636,27 @@ main:
576636
LDA $DC01
577637
AND #%10000000
578638
BEQ @reset
579-
JMP 64738
639+
LDA #$FF
640+
STA 1
641+
JMP ($FFFC)
642+
643+
644+
.IFDEF MEGA65
645+
skip_mega_reg_tab:
646+
.BYTE 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ; $0X
647+
.BYTE 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ; $1X
648+
.BYTE 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ; $2X
649+
.BYTE 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ; $3X
650+
.BYTE 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ; $4X
651+
.BYTE 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ; $5X
652+
.BYTE 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ; $6X
653+
.BYTE 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ; $7X
654+
.BYTE 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ; $8X
655+
.BYTE 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ; $9X
656+
.BYTE 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ; $AX
657+
.BYTE 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ; $BX
658+
.BYTE 1,1,1,1, 1,1,1,1, 1,0,0,0, 0,0,0,0 ; $CX
659+
.BYTE 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ; $DX
660+
.BYTE 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ; $EX
661+
.BYTE 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 ; $FX
662+
.ENDIF

prg-files/c64_play.prg

4 Bytes
Binary file not shown.

prg-files/m65_play.prg

339 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)