Add comments

This commit is contained in:
Byron Lathi 2019-06-05 01:06:10 -04:00
parent 902e773330
commit 47aba92ec6
5 changed files with 98 additions and 52 deletions

View File

@ -2,9 +2,20 @@ ca65 V2.17 - Git 644d623
Main file : src\world.asm
Current file: src\world.asm
000000r 1 ; world.asm
000000r 1 ;
000000r 1 ; The world file contains the following:
000000r 1 ; * The current world, stored as an array of bytes refering
000000r 1 ; to the tile type they represent
000000r 1 ; * The item map, which stores all of the items to be drawn
000000r 1 ; on top of any of the applicable items, namely conveyor belts
000000r 1 ; * Routines for getting the current 10x10 window from the larger
000000r 1 ; world.
000000r 1
000000r 1 .export World
000000r 1
000000r 1 World:
000000r 1 World: ; This is the array which stores all of the world data.
000000r 1 ; Right now this is just 10x10, so no other methods are needed.
000000r 1 02 00 00 00 .byte 02, 00, 00, 00, 00, 00, 00, 00, 00, 00
000004r 1 00 00 00 00
000008r 1 00 00

View File

@ -1,3 +1,11 @@
; display.asm
;
; this file controls drawing to the screen.
; The draw routine here draws one 14x16 tiles
; at a time, using the coordinate and type specified
; in the zeropage locations degined in display.inc
.include "monitor.inc"
.include "display.inc"
.include "tiles.inc"
@ -15,22 +23,22 @@
.define PLAYER_Y GRID_HEIGHT/2
.define ADDR_1 $19
.define ADDR_2 $1B
.define TILE2D $abc
.define ADDR_1 $19 ; First block line address
.define ADDR_2 $1B ; Second block line address
.define TILE2D $abc ; non-zeropage placeholder for tile adderss.
draw: ldx TILENUM ;num
lda TILES, X
sta patch_1+1
sta patch_2+1
draw: ldx TILENUM ; This section gets the type of tile to draw.
lda TILES, X ; It then loads the address of the tile to draw
sta patch_1+1 ; and changes all references to the placeholder
sta patch_2+1 ; address to the address of the tile to draw.
sta patch_3+1
sta patch_4+1
sta patch_4+1 ; this first part gets the low byte
sta patch_5+1
sta patch_6+1
sta patch_7+1
sta patch_8+1
lda TILES+1, X
lda TILES+1, X ; and this second part gets the high byte.
sta patch_1+2
sta patch_2+2
sta patch_3+2
@ -40,20 +48,20 @@ draw: ldx TILENUM ;num
sta patch_7+2
sta patch_8+2
ldx #00
ldy TILECD
lda HGR_GRID,Y
sta ADDR_1
ldx #00 ; Start x, the counter, to 0.
ldy TILECD ; Set y to the coordinate to draw to.
lda HGR_GRID,Y ; Load the screen address for that coordinate
sta ADDR_1 ; Store that to address 1
clc
adc #$80
sta ADDR_2
lda HGR_GRID+1,Y
sta ADDR_1+1
adc #$80 ; Add $80 to get the block below that
sta ADDR_2 ; Store that to address 2
lda HGR_GRID+1,Y ; Get the high bytes for those two, which will be the
sta ADDR_1+1 ; same since the tiles never cross the interleaving pattern.
sta ADDR_2+1
.define ITER1 #$20
.define ITER1 #$20 ; $20 means the first block is done.
lin1t8: ldy #00
patch_1:
lda TILE2D,X
patch_1: ; Loop through the first 8 lines, drawing the value from the tile
lda TILE2D,X ; data to the screen memory
sta (ADDR_1),Y
inx
iny
@ -76,10 +84,10 @@ patch_4:
adc #$04
sta ADDR_1+1
cpx ITER1
bne lin1t8
bne lin1t8 ; Once that is over, go down to the next 8 lines.
clc
.define ITER2 #$40
lin916: ldy #00
.define ITER2 #$40 ; The x counter keeps going to access the rest of the tile data
lin916: ldy #00 ; Y resets to go back to the beginning of screen memory offset
patch_5:
lda TILE2D,X
sta (ADDR_2),Y
@ -104,12 +112,12 @@ patch_8:
adc #$04
sta ADDR_2+1
cpx ITER2
bne lin916
bne lin916 ; Do that till the end, then you're done.
rts
.DATA
HGR_GRID:
; The HGR grid is every location that a tile can be drawn.
HGR_GRID: ; It is a 10x10 grid.
.word $2000, $2004, $2008, $200C, $2010, $2014, $2018, $201C, $2020, $2024
.word $2100, $2104, $2108, $210C, $2110, $2114, $2118, $211C, $2120, $2124
.word $2200, $2204, $2208, $220C, $2210, $2214, $2218, $221C, $2220, $2224

View File

@ -8,52 +8,54 @@
.CODE
_main:
jsr HGR
jsr HGR ; Hires setup stuff
jsr BKGND
loop: jsr view
jsr update
jsr _delay;
jmp loop;
view: ldx #00
view1: lda World,x
sta TILENUM
txa
loop: jsr view ; view draws all tiles to the screen
jsr update ; update runs the "game logic" (more to come)
jsr _delay; ; to every tile, which animates belts and assemblers
jmp loop; ; for now. Delay will probably go away later once
; everything slows down.
view: ldx #00 ; View loop, x starts at 0.
view1: lda World,x ; Get the tile type at the coordinate
sta TILENUM ; Store that as the tile nuber
txa ; Multiply x by 2
asl
sta TILECD
jsr draw
lda TILECD
lsr
sta TILECD ; Store that as the tile coordinate
jsr draw ; Draw that tile
lda TILECD ; Grab the tile coordinate and divide by 2, since
lsr ; draw uses up the x value. This gets it back.
tax
inx
inx ; Incrase x until 100, all tiles have been drawn.
cpx #100
bne view1
rts
update: ldx #00
update1:lda World,x
ckconv: cmp #02
beq upconv
update: ldx #00 ; This loop just updates any animated tiles, like conveyors.
update1:lda World,x ; Load every world coordinate
ckconv: cmp #02 ; Check if it is one of the three conveyor positions
beq upconv ; Jump if it is
cmp #04
beq upconv
cmp #06
beq upconv2
beq upconv2 ; Jump if it needs to be reset
ckasmb:
inx
cpx #100
bne update1
rts
upconv: clc
upconv: clc ; Add 2 to the tile type, moving it forward 1.
adc #02
sta World,x
jmp ckasmb
upconv2:lda #02
upconv2:lda #02 ; Set the tile type back to 2, reseting it.
sta World,x
jmp ckasmb
_delay:
lda #00
_delay: ; Delay loop just adds a bunch of numbers
lda #00 ; together to waste time.
ldx #00
_delay1:adc #01
cmp #$ff

View File

@ -1,5 +1,19 @@
; tiles.asm
;
; The tiles file stores all of the different tile and item types.
; The TILES location stores the locations of all of the tile types.
; The ITEMS location stores the location of all of the item types.
;
; Currently items are not implemented yet so it is only tiles right now.
.export TILES
; This is the tile section. Each tile is 14x16, which translates to 4 bytes x 16 lines.
; Most of these were generated with a processing program I wrote which allows you to
; draw on the screen and then export that as hexadecimal data.
; Each time a new tile is created, it's label is added to the TILES section to be
; referenced to in the world array and drawn in the drawing loop.
TILES:
.word GRASS, CONVEYOR1_1, CONVEYOR1_2, CONVEYOR1_3
.word INSERTER1_1, INSERTER1_2, INSERTER1_3,ASSEMBLER1_1

View File

@ -1,6 +1,17 @@
; world.asm
;
; The world file contains the following:
; * The current world, stored as an array of bytes refering
; to the tile type they represent
; * The item map, which stores all of the items to be drawn
; on top of any of the applicable items, namely conveyor belts
; * Routines for getting the current 10x10 window from the larger
; world.
.export World
World:
World: ; This is the array which stores all of the world data.
; Right now this is just 10x10, so no other methods are needed.
.byte 02, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 00, 00, 00, 00, 00, 00, 00, 00, 00
.byte 00, 02, 02, 02, 14, 02, 02, 02, 00, 00