junglejourney

changeset 15:551e7b2ddacd

Started to move the BASIC code into the main assembly code.
author David Boddie <david@boddie.org.uk>
date Sat Aug 13 02:41:00 2011 +0200
parents f6c6beddf999
children acc98c3592fd
files build.py mapcode.oph
diffstat 2 files changed, 126 insertions(+), 3 deletions(-) [+]
line diff
     1.1 --- a/build.py	Fri Aug 12 01:31:35 2011 +0200
     1.2 +++ b/build.py	Sat Aug 13 02:41:00 2011 +0200
     1.3 @@ -49,11 +49,21 @@
     1.4      # Planned memory map
     1.5      # 1900 CODE (map)
     1.6      # 1x00 space
     1.7 -    # 4E00 character table (256/4 entries)
     1.8 +    # 4F00 character table (128/4 entries)
     1.9      #   n   type
    1.10      #   n+1 counter/direction
    1.11      #   n+2 x position (0-19, top bit 0-1)
    1.12      #   n+3 y position (0-27, top bit 0-1)
    1.13 +    #
    1.14 +    #   first character is always the player
    1.15 +    #   second character is always the player's weapon
    1.16 +    #   new characters are added 
    1.17 +    #
    1.18 +    # 4FF0 current room (i, j)
    1.19 +    # 4FF2 lives
    1.20 +    # 4FF4 score (two bytes)
    1.21 +    # 4FFB palette workspace (enough for one 5 byte palette entry)
    1.22 +    #
    1.23      # 5000 CHARS (character sprites)
    1.24      # 5600 SPRITES (map)
    1.25      # 5780 space
    1.26 @@ -65,7 +75,6 @@
    1.27      system("ophis mapcode.oph CODE")
    1.28      code = open("CODE").read()
    1.29      code_start = 0x1900
    1.30 -    files.append(("CODE", code_start, code_start, code))
    1.31      
    1.32      addresses = []
    1.33      i = 0
    1.34 @@ -75,6 +84,8 @@
    1.35                  addresses.append(code_start + i + 1)
    1.36          i += 1
    1.37      
    1.38 +    files.append(("CODE", code_start, addresses[-1], code))
    1.39 +    
    1.40      data = makesprites.read_sprites(makesprites.chars)
    1.41      files.append(("CHARS", 0x5000, 0x5000, data))
    1.42      
     2.1 --- a/mapcode.oph	Fri Aug 12 01:31:35 2011 +0200
     2.2 +++ b/mapcode.oph	Sat Aug 13 02:41:00 2011 +0200
     2.3 @@ -391,7 +391,12 @@
     2.4      jsr plot
     2.5      rts
     2.6  
     2.7 -plot_room:          ; $78,$79 = i,j
     2.8 +plot_room:          ; $78,$79 = i,j (from $4ff0,$4ff1)
     2.9 +    lda $4ff0
    2.10 +    sta $78
    2.11 +    lda $4ff1
    2.12 +    sta $79
    2.13 +
    2.14      lda #$00
    2.15      sta $72
    2.16      lda #$58
    2.17 @@ -493,6 +498,20 @@
    2.18      rts
    2.19  
    2.20  
    2.21 +; Sprite data stored in memory: 00 11 22 33 44 55 66 77 88 99 aa bb
    2.22 +;
    2.23 +; Write to screen in this arrangement:
    2.24 +; -- --
    2.25 +; 00 22
    2.26 +;
    2.27 +; 11 33
    2.28 +; 44 66
    2.29 +;
    2.30 +; 55 77
    2.31 +; 88 aa
    2.32 +;
    2.33 +; 99 bb
    2.34 +
    2.35  plot12x24_y1:           ; $70,$71=source address
    2.36                          ; $72,$73=destination address
    2.37  
    2.38 @@ -601,3 +620,96 @@
    2.39      sta $74
    2.40  exit_keys:
    2.41      rts
    2.42 +
    2.43 +
    2.44 +set_palette:
    2.45 +                    ; $70=logical colour
    2.46 +                    ; $71=physical colour
    2.47 +    lda $70
    2.48 +    sta $4ffb
    2.49 +    lda $71
    2.50 +    sta $4ffc
    2.51 +    lda #0
    2.52 +    sta $4ffd
    2.53 +    sta $4ffe
    2.54 +    sta $4fff
    2.55 +
    2.56 +    lda #$c         
    2.57 +    ldx #$fb
    2.58 +    ldy #$4f
    2.59 +    jsr $fff1
    2.60 +    rts
    2.61 +
    2.62 +sprites_file_name: .byte "SPRITES", 13
    2.63 +chars_file_name: .byte "CHARS", 13
    2.64 +
    2.65 +sprites_block: .byte <sprites_file_name, >sprites_file_name
    2.66 +               .byte 0, $56, 0, 0
    2.67 +               .byte 0, $56, 0, 0
    2.68 +               .byte $80, $01, 0, 0
    2.69 +               .byte $80, $57, 0, 0
    2.70 +
    2.71 +init:
    2.72 +    lda #255
    2.73 +    ldx #<sprites_block
    2.74 +    ldy #>sprites_block
    2.75 +    jsr $ffdd
    2.76 +
    2.77 +    lda #22         ; MODE 5
    2.78 +    jsr $ffee
    2.79 +    lda #5
    2.80 +    jsr $ffee
    2.81 +
    2.82 +    lda #23         ; disable flashing cursor
    2.83 +    jsr $ffee
    2.84 +    lda #1
    2.85 +    jsr $ffee
    2.86 +    ldx #7
    2.87 +    cursor_loop:
    2.88 +        lda #0
    2.89 +        jsr $ffee
    2.90 +        dex
    2.91 +        bpl cursor_loop
    2.92 +
    2.93 +    lda #2
    2.94 +    sta $70
    2.95 +    lda #2
    2.96 +    sta $71
    2.97 +    jsr set_palette
    2.98 +
    2.99 +    lda #3
   2.100 +    sta $70
   2.101 +    lda #3
   2.102 +    sta $71
   2.103 +    jsr set_palette
   2.104 +
   2.105 +    rts
   2.106 +
   2.107 +start_new_game:
   2.108 +    lda #5
   2.109 +    sta $4ff0
   2.110 +    lda #5
   2.111 +    sta $4ff1
   2.112 +
   2.113 +    rts
   2.114 +
   2.115 +main:
   2.116 +    jsr init
   2.117 +
   2.118 +    main_loop:
   2.119 +
   2.120 +        main_wait_loop:
   2.121 +            lda #129
   2.122 +            ldx #157
   2.123 +            ldy #255
   2.124 +            jsr $fff4
   2.125 +            cpy #255
   2.126 +            bne main_wait_loop
   2.127 +
   2.128 +        jsr start_new_game
   2.129 +        jsr plot_room
   2.130 +
   2.131 +        game_loop:
   2.132 +
   2.133 +        jmp main_loop
   2.134 +    rts