• entries
104
102
• views
259430

# First step explained in detail

11623 views

As threatened the first step detailed. I reckon that the first step is overwhelming if it's your first voyage into C64 game programming. There's quite a few assumptions made about the viewer's knowledge and the later steps won't get exactly easier.

A note about the !zone macro. ACME allows for global and local labels. A local label is starting with a . and is only visible inside a zone. This allows for easier reuse of common names like loop or retry.

This snippet tells the ACME cross compiler to assemble the result into the file "jmain.prg" with the cbm (Commodore Business Machines) type. This basically boils down to the well known .prg format which contains a word with the loading address at the start followed by the assembly.

;compile to this filename
!to "jmain.prg",cbm

The next snipped just defines a constant. I try to use them throughout so you can understand where I'm putting bytes at. The value 52224 is the address of the screen buffer, where 25 lines a 40 characters are stored continously. This is not the default memory location for the screen, a part of this base code relocates the screen.

;define constants here
SCREEN_CHAR = 52224

Now a very interesting piece which took me longer to work out than it should have. A C64 has two types of files, Basic files and machine code files. A Basic file can be started by RUN, a machine code file just contains the code and usually must be jumped at with the SYS command. Any half decent game will provide a proper Basic kick start that jumps directly at the machine code.

To allow for this we set the file start address to $801 (2049), the default Basic start. The file content starts out with the tokenized bytes of a simple Basic line calling SYS for us. The line is built by a word containing the address of the next Basic line. Following is a word with the line number (10 in our sample). After that the token for the SYS command ($9e) followed by a space ($20) and the ASCII representation of the target address (2064 in our sample). After that there is one zero byte marking the end of the line. The next zero word represents the end of the Basic file. I've got some extra zero bytes which are actually wrong but also don't really hurt. ;this creates a basic start *=$801 ;SYS 2064
!byte $0C,$8,$0A,$00,$9E,$20,$32,$30,$36,$34,$00,$00,$00,$00,$00 The next snippet disables any visible sprites, relocates the VICs memory bank (resulting in a relocated screen buffer and charset address).  ;init sprite registers ;no visible sprites lda #0 sta VIC_SPRITE_ENABLE ;set charset lda #$3c
sta VIC_MEMORY_CONTROL

;VIC bank
lda CIA_PRA
and #$fc sta CIA_PRA This piece is the main game loop. It's rather easy, we increase the border color (resulting in flashing), increase the top left character on the screen, wait for the vertical blank (not exactly but to the effect) and rerun the loop.  ;the main game loop GameLoop ;border flashing inc VIC_BORDER_COLOR ;top left char inc SCREEN_CHAR jsr WaitFrame jmp GameLoop This snippet is quite interesting. The C64 allows you to read the current raster line on the screen that is currently being redrawn. The code checks for a certain raster position at the bottom of the screen to sync the game to the computer's display speed. In detail we're waiting for the raster line to NOT be the position we want to wait for. Once we are on any line but the wanted we now really wait for our raster line to appear. This avoids the problem when the routine is called too fast in succession and we end up on the same raster line. !zone WaitFrame ;wait for the raster to reach line$f8
;this is keeping our timing stable

;are we on line $F8 already? if so, wait for the next full screen ;prevents mistimings if called too fast WaitFrame lda$d012
cmp #$F8 beq WaitFrame ;wait for the raster to reach line$f8 (should be closer to the start of this line this way)
.WaitStep2
lda $d012 cmp #$F8
bne .WaitStep2

rts

This is pretty interesting. Is there anything to show up yet? I mean, screenshots.

Of course I didn't want to start the steps before having something actually playable. The current implementation is at step 37, looking like this. It's nothing ground breaking, but should show some basic things that come into play.

[img]http://www.georg-rottensteiner.de/webmisc/supernatural_gamedev_wip1.png[/img]

[img]http://www.georg-rottensteiner.de/webmisc/supernatural_gamedev_wip2.png[/img]

Hi, I started to follow your tutorial, I'm just starting out with assembly schedules. In this code snippet that follows if I understand correctly, font, video, and bitmap memory is reallocated

Lda # $3c Is VIC_MEMORY_CONTROL The character memory is at the$ 3000 address, that bitmpa at $2000, and the video at$ 0c00.

Why, then, the characters taken from j.chr are located starting at \$ F000.

Thank you

Nicola

## Create an account

Register a new account