;----------------------------------------------------------------------------- ; edit.inc ; Part of penetrator, the zx spectrum game, made for Apple II ; ; Stefan Wessels, 2019 ; This is free and unencumbered software released into the public domain. ;----------------------------------------------------------------------------- .segment "CODE" ;----------------------------------------------------------------------------- .proc editLoop jsr drawClearScreen ; make sure the screen is clear before adjusting the jsr editInit jsr editLoadStage lda #2 sta updateHUD loop: jsr inputEdit beq :+ jsr editHandleKeys lda pause ; pause is quit flag in endit beq :+ rts : clc jsr terrainShow ; show terrain 1st because it collides with nothing jsr drawEnemies ; enemies collide with nothing in edit mode jsr editDrawCursor lda updateHUD beq :+ jsr uiShowEditLabels : jsr drawPresent ; flip layers 0/1 (bring backLayer to visible) jmp loop .endproc ;----------------------------------------------------------------------------- .proc editHandleKeys cmp #'6' ; 6 or bigger - not a stage command bcs notnum cmp #'1' ; less than 1 - not a stage command bcc notnum sbc #'1' ; stages are 0 based sta stage lda #AUDIO_UI_TICK ; make a sound sta audioFrame jsr serviceAudio lda #0 ; reset where the buffers will start sta bufferInsert jsr drawClearScreen jsr editLoadStage ; get the right stage at the right place jmp uiShowEditLabels ; update the HUD notnum: cmp #$1b ; ESC key bne notQuit lda #AUDIO_UI_TICK ; make a sound sta audioFrame jsr serviceAudio lda #1 sta pause ; abuse pause to signal quit rts notQuit: cmp #'c' ; c or C for help beq help cmp #'C' bne notHelp help: lda #AUDIO_UI_TICK ; make a sound sta audioFrame jsr serviceAudio jmp uiShowEditHelp notHelp: cmp #'s' ; s or S for save beq save cmp #'S' bne notSave save: lda #AUDIO_UI_TICK ; make a sound sta audioFrame jsr serviceAudio lda #0 ; a 0 is save jsr uiFileLoadSave jmp editLoop notSave: cmp #'l' ; l or L for load beq load cmp #'L' bne done load: lda #AUDIO_UI_TICK ; make a sound sta audioFrame jsr serviceAudio lda #1 ; a 1 is load jsr uiFileLoadSave jmp editLoop done: clc rts .endproc ;----------------------------------------------------------------------------- ; Move the world left (feels like YOU are moving right) ; will update the stage when a stage boundary is crossed and will then ; update the HUD .proc editGameWorldRight zaWorldPtr = tempBlock + 14 ; 2 bytes for a ptr lda stage ; only scroll right while the stage cmp #4 ; isn't 5 (0 based so 4). Stage 5 bcc :+ ; cannot be edited rts : jsr gameWorldMove ; use the game move code lda zWorldPtr + 1 ; but then calculate a point where the stage marker might be sta zaWorldPtr + 1 lda zWorldPtr sec sbc #((XSIZE+3)*3) sta zaWorldPtr bcs :+ dec zaWorldPtr + 1 : ldy #2 ; and read the enemy byte lda (zaWorldPtr), y bit Bit7Mask ; and see if this is a stage change beq :+ inc stage ; bit was set so change stage lda #2 ; and update the HUD sta updateHUD : inc bufferDraw ; the bufferDraw (col 0) is also one more to the right rts .endproc ;----------------------------------------------------------------------------- ; Scroll to the left, updating the stage boundary and adding enemies as needed. .proc editGameWorldLeft leftWorldPtr = tempBlock + 14 lda zWorldPtr + 1 ; get the left edge insert point by subtracting sta leftWorldPtr + 1 ; XSIZE+3 from the right edge. XSIZE-1 is the current lda zWorldPtr ; left screen col. +3 is 4 past, which is the width sec ; of a radar that could now scroll on-screen sbc #((XSIZE+3)*3) ; the buffer will have proper height data for at least sta leftWorldPtr ; 2 of these 3 cols to the left - see editLoadStage bcs :+ dec leftWorldPtr + 1 : lda leftWorldPtr + 1 ; see if this new dest is <= the world start. cmp #>worldDataStart ; if it is then don't scroll any further left, just exit beq :+ ; hi equal to worldStart hi, so test low bcs leftOk ; hi > worldStart hi so good to go done: rts : lda leftWorldPtr cmp #