Skip to content

Commit

Permalink
R37
Browse files Browse the repository at this point in the history
Updated the code to work with R37 of the emulator
  • Loading branch information
StewBC committed May 24, 2020
1 parent ee8bdea commit d088788
Show file tree
Hide file tree
Showing 16 changed files with 205 additions and 251 deletions.
9 changes: 3 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
*.code-workspace
/.vscode/
/obj/
/penetrator.*
40 changes: 17 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ LIBS :=
# Default: none
CONFIG :=

# Additional C assembler flags and options.
# Additional C compiler flags and options.
# Default: none
CFLAGS =

Expand Down Expand Up @@ -64,6 +64,7 @@ POSTEMUCMD :=
# VICE emulators.
ifeq ($(OS),Windows_NT)
VICE_HOME :=
CX16_HOME :=
else
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
Expand All @@ -80,22 +81,22 @@ STATEFILE := Makefile.options
###################################################################################

###################################################################################
### Mapping abstract options to the actual assembler, assembler and linker flags ###
### Predefined assembler, assembler and linker flags, used with abstract options ###
### Mapping abstract options to the actual compiler, assembler and linker flags ###
### Predefined compiler, assembler and linker flags, used with abstract options ###
### valid for 2.14.x. Consult the documentation of your cc65 version before use ###
###################################################################################

# assembler flags used to tell the assembler to optimise for SPEED
# Compiler flags used to tell the compiler to optimise for SPEED
define _optspeed_
CFLAGS += -Oris
endef

# assembler flags used to tell the assembler to optimise for SIZE
# Compiler flags used to tell the compiler to optimise for SIZE
define _optsize_
CFLAGS += -Or
endef

# assembler and assembler flags for generating listings
# Compiler and assembler flags for generating listings
define _listing_
CFLAGS += --listing $$(@:.o=.lst)
ASFLAGS += --listing $$(@:.o=.lst)
Expand Down Expand Up @@ -149,17 +150,8 @@ ifeq ($(OBJDIR),)
endif
TARGETOBJDIR := $(OBJDIR)/$(TARGETS)

# On Windows it is mandatory to have CC65_HOME set. So do not unnecessarily
# rely on cl65 being added to the PATH in this scenario.
ifdef CC65_HOME
CC := $(CC65_HOME)/bin/cl65
else
CC := cl65
endif

# Default emulator commands and options for particular targets.
# Set EMUCMD to override.
cx16_EMUCMD := $(VICE_HOME)x16emu -run -prg
c64_EMUCMD := $(VICE_HOME)x64 -kernal kernal -VICIIdsize -autostart
c128_EMUCMD := $(VICE_HOME)x128 -kernal kernal -VICIIdsize -autoload
vic20_EMUCMD := $(VICE_HOME)xvic -kernal kernal -VICdsize -autoload
Expand All @@ -170,6 +162,9 @@ c16_EMUCMD := $(VICE_HOME)xplus4 -ramsize 16 -TEDdsize -autoload
cbm510_EMUCMD := $(VICE_HOME)xcbm2 -model 510 -VICIIdsize -autoload
cbm610_EMUCMD := $(VICE_HOME)xcbm2 -model 610 -Crtcdsize -autoload
atari_EMUCMD := atari800 -windowed -xl -pal -nopatchall -run
apple2_EMUCMD := $(AWIN_HOME)AppleWin.exe -d1
atmos_EMUCMD := $(ORIC_HOME)Oricutron.exe -t
cx16_EMUCMD := $(CX16_HOME)x16emu -run -prg

ifeq ($(EMUCMD),)
EMUCMD = $($(CC65TARGET)_EMUCMD)
Expand All @@ -181,10 +176,10 @@ endif

# The "Native Win32" GNU Make contains quite some workarounds to get along with
# cmd.exe as shell. However it does not provide means to determine that it does
# actually activate those workarounds. Especially does $(SHELL) NOT contain the
# actually activate those workarounds. Especially $(SHELL) does NOT contain the
# value 'cmd.exe'. So the usual way to determine if cmd.exe is being used is to
# execute the command 'echo' without any parameters. Only cmd.exe will return a
# non-empy string - saying 'ECHO is on/off'.
# non-empty string - saying 'ECHO is on/off'.
#
# Many "Native Win32" programs accept '/' as directory delimiter just fine. How-
# ever the internal commands of cmd.exe generally require '\' to be used.
Expand Down Expand Up @@ -297,29 +292,28 @@ $(TARGETOBJDIR):
vpath %.c $(SRCDIR)/$(TARGETLIST) $(SRCDIR)

$(TARGETOBJDIR)/%.o: %.c | $(TARGETOBJDIR)
$(CC) -t $(CC65TARGET) -c --create-dep $(@:.o=.d) $(CFLAGS) -o $@ $<
cl65 -t $(CC65TARGET) -c --create-dep $(@:.o=.d) $(CFLAGS) -o $@ $<

vpath %.s $(SRCDIR)/$(TARGETLIST) $(SRCDIR)

$(TARGETOBJDIR)/%.o: %.s | $(TARGETOBJDIR)
$(CC) -t $(CC65TARGET) -c --create-dep $(@:.o=.d) $(ASFLAGS) -o $@ $<
cl65 -t $(CC65TARGET) -c --create-dep $(@:.o=.d) $(ASFLAGS) -o $@ $<

vpath %.asm $(SRCDIR)/$(TARGETLIST) $(SRCDIR)

$(TARGETOBJDIR)/%.o: %.asm | $(TARGETOBJDIR)
$(CC) -t $(CC65TARGET) -c --create-dep $(@:.o=.d) $(ASFLAGS) -o $@ $<
cl65 -t $(CC65TARGET) -c --create-dep $(@:.o=.d) $(ASFLAGS) -o $@ $<

vpath %.a65 $(SRCDIR)/$(TARGETLIST) $(SRCDIR)

$(TARGETOBJDIR)/%.o: %.a65 | $(TARGETOBJDIR)
$(CC) -t $(CC65TARGET) -c --create-dep $(@:.o=.d) $(ASFLAGS) -o $@ $<
cl65 -t $(CC65TARGET) -c --create-dep $(@:.o=.d) $(ASFLAGS) -o $@ $<

$(PROGRAM): $(CONFIG) $(OBJECTS) $(LIBS)
$(CC) -t $(CC65TARGET) $(LDFLAGS) -o $@ $(patsubst %.cfg,-C %.cfg,$^)
cl65 -t $(CC65TARGET) $(LDFLAGS) -o $@ $(patsubst %.cfg,-C %.cfg,$^)

test: $(PROGRAM)
$(PREEMUCMD)
@echo $(EMUCMD) $<
$(EMUCMD) $<
$(POSTEMUCMD)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# penetrator
Remake of the ZX Spectrum game for the Commander X16.
Remake of the ZX Spectrum game for the Commander X16. (Emu R37)

1. INTRODUCTION

Expand Down
39 changes: 6 additions & 33 deletions src/defs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,18 @@
; This is free and unencumbered software released into the public domain.

;-----------------------------------------------------------------------------
; VERA
VERA_ADDR_LO = $9F20
VERA_ADDR_MID = $9F21
VERA_ADDR_HI = $9F22
VERA_DATA0 = $9F23
VERA_DATA1 = $9F24
VERA_CTRL = $9F25
VERA_IEN = $9F26
VERA_ISR = $9F27

DC_VIDEO = $00
DC_HSCALE = $01
DC_VSCALE = $02
DC_BORDER_COLOR = $03
DC_HSTART_L = $04
DC_HSTOP_L = $05
DC_VSTART_L = $06
DC_VSTOP_L = $07
DC_STARTSTOP_H = $08

VERA_regs_hi = $0F
VERA_regs_layer0 = $2000
VERA_regs_layer1 = $3000
; VRAM locations
ram_layer0 = $0000 ; after title, layer 0 memory here
ram_layer1 = $5000 ; after title, layer 1 memory here
gfx_layer1 = $0000 ; the 4bpp title screen memory start

Ln_CTRL0 = $00
Ln_CTRL1 = $01
Ln_TILE_BASE_H = $05
Ln_BM_PAL_OFFS = $07
;-----------------------------------------------------------------------------
; System locations
; These are for r34 - find them in rom.sym in the emulator folder
TIME_1 = $0293 ; TIME is at $0292 - +1 is APPROX 3.75 sec/tick
TIME_2 = $0294 ; TIME is at $0292 - +2 is the 16 ms counter
NDX = $029E
JOY1 = $02BC
GETJOY = $FF06
; These are for r37 - find them in kernal.sym in the emulator folder
NDX = $A00A
TIME_1 = $A038 ; TIMER is at $A037 (bank 0) - +1 is APPROX 3.75 sec/tick
TIME_2 = $A039 ; +2 is the jiffy counter (also at $A03D?)
JOYGET = $FF56
SETLFS = $FFBA
SETNAM = $FFBD
LOAD = $FFD5
Expand Down
62 changes: 34 additions & 28 deletions src/draw.inc
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@
sta backLayer
beq :+

vpoke VERA_regs_hi, VERA_regs_layer0 + Ln_CTRL0, $a1
vpoke VERA_regs_hi, VERA_regs_layer1 + Ln_CTRL0, $a0
lda VERA::DISP::VIDEO
and #%11001111 ; both latyers off
ora #%00010000 ; turn layer 0 on
sta VERA::DISP::VIDEO

lda #>ram_layer1
sta zVramH
rts

:
vpoke VERA_regs_hi, VERA_regs_layer0 + Ln_CTRL0, $a0
vpoke VERA_regs_hi, VERA_regs_layer1 + Ln_CTRL0, $a1
lda VERA::DISP::VIDEO
and #%11001111 ; both latyers off
ora #%00100000 ; turn layer 1 on
sta VERA::DISP::VIDEO

lda #>ram_layer0
sta zVramH
rts
Expand All @@ -41,19 +47,19 @@
pha
clc
lda rowL, y ; strictly also adc layersL, x but always 256-byte aligned
sta VERA_ADDR_LO
sta VERA::ADDR ;LO
lda rowH, y
adc layersH, x
sta VERA_ADDR_MID
sta VERA::ADDR + 1 ;MID
lda #$10 ; 1 byte step size and 0 for top address
sta VERA_ADDR_HI
sta VERA::ADDR + 2 ;HI
pla ; put the # of rows in Y
tay
lda #$00
row:
ldx #XSIZE ; and all columns
:
sta VERA_DATA0 ; set to 0
sta VERA::DATA0 ; set to 0
dex
bne :-
dey
Expand Down Expand Up @@ -90,22 +96,22 @@ row:
asl
tax ; use as offset into palette table
lda #$1F ; set vera for palette entry
sta VERA_ADDR_HI
lda #>$1000
sta VERA_ADDR_MID
lda #<$1000
sta VERA_ADDR_LO
lda #$11 ; set vera for palette entry
sta VERA::ADDR + 2 ; HI
lda #>$FA00
sta VERA::ADDR + 1 ; MID
lda #<$FA00
sta VERA::ADDR ; LO

:
lda gamePalette, x ; store the palette into vera
sta VERA_DATA0
sta VERA::DATA0
inx
dey
bne :-

lda #$00 ; restore the HI addr to 0 (is assumed elsewhere)
sta VERA_ADDR_HI
sta VERA::ADDR + 2 ; HI

rts

Expand Down Expand Up @@ -137,19 +143,19 @@ row:
sta rows ; save as count for how many rows

lda #$10 ; to be sure, set the stride to 1
sta VERA_ADDR_HI
sta VERA::ADDR + 2 ; HI

loop:
lda rowL, y
adc x0 ; get the x y address
sta VERA_ADDR_LO
sta VERA::ADDR ; LO
lda rowH, y
adc zVramH
sta VERA_ADDR_MID
sta VERA::ADDR + 1 ; MID
lda plotCol ; get the plot color
ldx width ; get how wide to go
:
sta VERA_DATA0 ; write one row of pixels
sta VERA::DATA0 ; write one row of pixels
dex
bne :-
iny ; keep doing till
Expand Down Expand Up @@ -186,15 +192,15 @@ column:
rows:
lda rowL, y ; get the screen row start address, low byte
adc zaScreenColLocal ; add the column to the address
sta VERA_ADDR_LO ; set vera low address
sta VERA::ADDR ; set vera low address
lda rowH, y ; get the high byte of the screen row start
adc zVramH ; add the VRAM high byte (for which layer)
sta VERA_ADDR_MID ; set the Vera MID (high is already = 0)
sta VERA::ADDR + 1 ; set the Vera MID (high is already = 0)
offset:
lda spriteData, x ; this address is modified by the caller
sta zaDrawByte ; save the byte
eor VERA_DATA0 ; get what's on screen xor'd with what's being added
sta VERA_DATA0 ; save that to the screen
eor VERA::DATA0 ; get what's on screen xor'd with what's being added
sta VERA::DATA0 ; save that to the screen
and zaDrawByte ; mask off any bits that the sprite isn't setting
cmp zaDrawByte ; see if the sprite overlapped something there already
clc ; cmp can set carry. keep it clear
Expand Down Expand Up @@ -589,13 +595,13 @@ bullet:

clc ; put the bullet at height y col x on screen
adc rowL, y
sta VERA_ADDR_LO
sta VERA::ADDR
lda rowH, y
adc zVramH
sta VERA_ADDR_MID
sta VERA::ADDR + 1 ; MID
lda #$ff ; bullet is a solid line
eor VERA_DATA0
sta VERA_DATA0
eor VERA::DATA0
sta VERA::DATA0
cmp #$ff ; see if it hit something
beq next ; no collision, next (prev) column/bullet

Expand Down
13 changes: 7 additions & 6 deletions src/edit.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@

jsr drawClearScreen ; make sure the screen is clear before adjusting the

vpoke VERA_regs_hi, DC_VSCALE, VSCALE_GAME ; make the screen shorter to be more spectrum-like for gameplay
lda #VSCALE_GAME ; make the screen shorter to be more spectrum-like for gameplay
sta VERA::DISP::VSCALE

jsr editInit
jsr editLoadStage
Expand Down Expand Up @@ -288,7 +289,7 @@ missile:
print textEditDnArrow, playerShipX, 0, #$ff ; redraw arrow to fix out of top cursor overwrite

lda #$10 ; stride of 1
sta VERA_ADDR_HI
sta VERA::ADDR + 2 ; HI

lda #$87 ; cursor symbol
ldy #0
Expand All @@ -305,17 +306,17 @@ plotLoop:
lda rowL, y ; get the memory address
clc
adc playerShipX ; add in column
sta VERA_ADDR_LO ; point vera at memory
sta VERA::ADDR ; point vera at memory
lda rowH, y
adc layersH, x
sta VERA_ADDR_MID
sta VERA::ADDR + 1 ; MID

ldy zaFontOffset ; get the offset into the character
lda (zaFontL), y ; get the actual left character byte
sta VERA_DATA0 ; plot the left hand side
sta VERA::DATA0 ; plot the left hand side
iny ; go to next byte (right hand side of character)
lda (zaFontL), y
sta VERA_DATA0
sta VERA::DATA0
cpy #$0A ; cursor character is 5 rows high, * 2 is 10 bytes long
bcs done ; if 10 then done with the cursor
inc zaFontOffset ; move 2 bytes for last row plotted
Expand Down
6 changes: 3 additions & 3 deletions src/file.inc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
ldy #>textFileName
jsr SETNAM
lda #$00 ; logical number
ldx #$01 ; device 1
ldx #$08 ; device 8
ldy #$01 ; secondary address
jsr SETLFS

Expand All @@ -44,7 +44,7 @@
ldy #>textFileName
jsr SETNAM
lda #$00 ; logical number
ldx #$01 ; device 1
ldx #$08 ; device 8
ldy #$01 ; secondary address
jsr SETLFS
ldx #<worldDataStart
Expand All @@ -53,4 +53,4 @@
jsr LOAD ; call load to load the world
rts

.endproc
.endproc
Loading

0 comments on commit d088788

Please sign in to comment.