소스 검색

Add chopper: parallax-scrolling helicopter game with hazards and firefighting

cc65 C game logic over a ca65 engine (PAL):
- three-layer parallax (clouds, mountains, hills) with per-band $D016
  splits; band shifts and sub-pixel layer stepping in scroll.s
- one raster IRQ scheduler (mux.s) driving the band splits and a sprite
  multiplexer: 8 hazards + water spray on hardware sprites 3-7
- hazards (birds, balloons, jets) and tree fires in hazards.s; spray
  water to put fires out, tank refills on landing, burnt trees persist
- terrain from height maps built at startup; columns built ahead and
  background jobs scheduled by raster budget
- tools/gen_gfx.py generates all sprites and tiles (src/gfx.h, gfx.inc)

The self-test checks terrain, scrolling, the multiplexer and fire logic,
then flies 1000 demo frames, failing on any late frame, missed raster
split or scroll position jump.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
refactor/agent-workflow
부모
커밋
c82b7e4f04
10개의 변경된 파일과 2890개의 추가작업 그리고 0개의 파일을 삭제
  1. +12
    -0
      projects/chopper/c64project.json
  2. +41
    -0
      projects/chopper/src/dec.s
  3. +202
    -0
      projects/chopper/src/gfx.h
  4. +23
    -0
      projects/chopper/src/gfx.inc
  5. +17
    -0
      projects/chopper/src/hazards.inc
  6. +329
    -0
      projects/chopper/src/hazards.s
  7. +1108
    -0
      projects/chopper/src/main.c
  8. +480
    -0
      projects/chopper/src/mux.s
  9. +205
    -0
      projects/chopper/src/scroll.s
  10. +473
    -0
      projects/chopper/tools/gen_gfx.py

+ 12
- 0
projects/chopper/c64project.json 파일 보기

@@ -0,0 +1,12 @@
{
"name": "chopper",
"machine": "c64",
"language": "c",
"sources": ["src/*.c", "src/*.s"],
"flags": ["-Oirs"],
"disk": true,
"test": {
"expect": ["SPEED", "ALT", "WATER", "LIVES", "DEMO"],
"timeoutSeconds": 90
}
}

+ 41
- 0
projects/chopper/src/dec.s 파일 보기

@@ -0,0 +1,41 @@
; dec.s - 16-bit unsigned to five decimal screen-code digits, by subtraction.
; About 300 cycles; the C version with % and / cost over 4000.
;
; void __fastcall__ to_dec(unsigned v); result in decbuf[0..4], '0'-'9'

.export _to_dec, _decbuf
.importzp ptr1, tmp1

.segment "BSS"
_decbuf: .res 5

.segment "CODE"
_to_dec:
sta ptr1
stx ptr1+1
ldy #0
@digit: ldx #'0'
@sub: lda ptr1
sec
sbc lo_tab,y
sta tmp1
lda ptr1+1
sbc hi_tab,y
bcc @done
sta ptr1+1
lda tmp1
sta ptr1
inx
bne @sub
@done: txa
sta _decbuf,y
iny
cpy #4
bne @digit
lda ptr1
ora #'0'
sta _decbuf+4
rts

lo_tab: .byte <10000, <1000, <100, <10
hi_tab: .byte >10000, >1000, >100, >10

+ 202
- 0
projects/chopper/src/gfx.h 파일 보기

@@ -0,0 +1,202 @@
/* Generated by tools/gen_gfx.py - do not edit by hand. */
#ifndef GFX_H
#define GFX_H

#define FIRST_TILE 64
#define NUM_TILES 33
#define T_CL_TL 64
#define T_CL_TM1 65
#define T_CL_TM2 66
#define T_CL_TR 67
#define T_CL_BL 68
#define T_CL_BM 69
#define T_CL_BR 70
#define T_M_UP 71
#define T_M_DN 72
#define T_M_PEAK 73
#define T_M_UP_S 74
#define T_M_DN_S 75
#define T_M_PK_S 76
#define T_M_FL_S 77
#define T_M_SOLID 78
#define T_M_SNOW 79
#define T_M_ROCK 80
#define T_H_UP 81
#define T_H_DN 82
#define T_H_PEAK 83
#define T_H_FLAT 84
#define T_H_SOLID 85
#define T_TREE_TOP 86
#define T_TREE_TRUNK 87
#define T_PINE_TOP 88
#define T_PINE_MID 89
#define T_PINE_TRUNK 90
#define T_GRASS1 91
#define T_GRASS2 92
#define T_DIRT1 93
#define T_DIRT2 94
#define T_BURNT_TREE 95
#define T_BURNT_PINE 96

static const unsigned char tile_data[NUM_TILES * 8] = {
0x00,0x00,0x00,0x01,0x05,0x15,0x55,0x55, /* T_CL_TL */
0x00,0x14,0x55,0x55,0x55,0x55,0x55,0x55, /* T_CL_TM1 */
0x00,0x00,0x05,0x15,0x55,0x55,0x55,0x55, /* T_CL_TM2 */
0x00,0x00,0x40,0x50,0x54,0x54,0x55,0x55, /* T_CL_TR */
0x55,0x55,0x15,0x1A,0x0A,0x00,0x00,0x00, /* T_CL_BL */
0x55,0x55,0x55,0x99,0xAA,0x00,0x00,0x00, /* T_CL_BM */
0x55,0x55,0x54,0xA4,0xA0,0x00,0x00,0x00, /* T_CL_BR */
0x02,0x02,0x0B,0x0B,0x2F,0x2F,0xBF,0xBF, /* T_M_UP */
0xC0,0xC0,0xF0,0xF0,0xFC,0xFC,0xFF,0xFF, /* T_M_DN */
0x2C,0x2C,0x2F,0xBF,0xBF,0xBF,0xBF,0xFF, /* T_M_PEAK */
0x01,0x01,0x05,0x07,0x17,0x1F,0xBF,0xBF, /* T_M_UP_S */
0x40,0x40,0x50,0xD0,0xD4,0xF4,0xFC,0xFF, /* T_M_DN_S */
0x14,0x14,0x15,0x55,0x5D,0x7F,0xBF,0xBF, /* T_M_PK_S */
0x55,0x75,0xFF,0xF7,0xFF,0xFF,0xFF,0xFF, /* T_M_FL_S */
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF, /* T_M_SOLID */
0xDF,0xFF,0xF7,0xFF,0x7F,0xFF,0xFF,0xFF, /* T_M_SNOW */
0xFF,0xFB,0xEF,0xFF,0xFF,0xFF,0xFF,0xFF, /* T_M_ROCK */
0x01,0x05,0x07,0x1F,0x1F,0x7F,0x7F,0xFF, /* T_H_UP */
0x40,0x50,0xD0,0xF4,0xF4,0xFD,0xFD,0xFF, /* T_H_DN */
0x00,0x14,0x55,0x7D,0xFF,0xDF,0xFF,0xFF, /* T_H_PEAK */
0x55,0xFF,0xDF,0xFF,0xFF,0xF7,0xFF,0xFF, /* T_H_FLAT */
0xFF,0xDF,0xFF,0xFF,0xFD,0xFF,0xFF,0xFF, /* T_H_SOLID */
0x14,0x77,0x5F,0x7F,0xFF,0xFF,0x3C,0x28, /* T_TREE_TOP */
0x28,0x28,0x28,0x28,0x28,0x28,0x28,0xAA, /* T_TREE_TRUNK */
0x00,0x1C,0x1C,0x5F,0x7F,0x1C,0x5F,0x7F, /* T_PINE_TOP */
0x1C,0x5F,0x7F,0xFF,0x1C,0x5F,0x7F,0xFF, /* T_PINE_MID */
0x28,0x28,0x28,0x28,0x28,0x28,0x28,0xAA, /* T_PINE_TRUNK */
0x44,0x55,0xDD,0xFF,0xF7,0xFF,0xDF,0xFF, /* T_GRASS1 */
0x11,0x55,0x77,0xFF,0xDF,0xFF,0xFD,0xFF, /* T_GRASS2 */
0xAA,0xBA,0xAA,0xAB,0xBA,0xAA,0xFF,0xFF, /* T_DIRT1 */
0xAA,0xAA,0xAE,0xAA,0xEA,0xAE,0xFF,0xFF, /* T_DIRT2 */
0x82,0x22,0x88,0x28,0x88,0x28,0x28,0x28, /* T_BURNT_TREE */
0x08,0x28,0x88,0x28,0x2A,0x88,0x28,0x28, /* T_BURNT_PINE */
};

#define NUM_SPRITES 49
/* blocks: [pose*2] outline, [pose*2+1] fill; poses 0-11 = facing*6+tilt*2+rotor,
12-13 front view, then shadow big (28) and shadow small (29). */
#define SP_SHADOW_BIG 28
#define SP_SHADOW_SMALL 29
#define SP_BIRD 30
#define SP_BIRD2 31
#define SP_BALLOON 32
#define SP_JET_L 33
#define SP_JET_L2 34
#define SP_JET_R 35
#define SP_JET_R2 36
#define SP_BOOM 37
#define SP_BOOM2 38
#define SP_BOOM3 39
#define SP_BLANK 40
#define SP_FIRE 41
#define SP_FIRE2 42
#define SP_FIRE_S 43
#define SP_FIRE_S2 44
#define SP_SPRAY 45
#define SP_SPRAY2 46
#define SP_STEAM 47
#define SP_STEAM2 48
static const unsigned char sprite_data[NUM_SPRITES * 64] = {
/* 0: f0 t0 r0 outline */
0,0,0,0,0,0,0,0,0,255,255,255,64,12,0,64,63,0,64,64,192,160,128,48,161,0,8,158,0,4,128,0,2,191,0,1,65,0,1,64,128,2,0,127,254,0,32,32,1,255,252,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 1: f0 t0 r0 fill */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42,0,128,170,128,128,170,144,170,170,148,170,255,148,170,255,165,0,170,170,0,170,168,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 2: f0 t0 r1 outline */
0,0,0,0,0,0,0,0,0,3,255,192,0,12,0,160,63,0,64,64,192,160,128,48,161,0,8,158,0,4,128,0,2,191,0,1,65,0,1,160,128,2,0,127,254,0,32,32,1,255,252,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 3: f0 t0 r1 fill */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,42,0,128,170,128,128,170,144,170,170,148,170,255,148,170,255,165,0,170,170,0,170,168,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 4: f0 t1 r0 outline */
0,0,0,240,0,0,79,240,0,64,15,240,64,60,15,160,79,0,160,128,192,145,0,48,142,0,0,176,0,8,79,0,4,65,0,2,0,128,1,0,112,1,0,47,242,1,240,46,0,15,240,0,0,12,0,0,0,0,0,0,0,0,0,0,
/* 5: f0 t1 r0 fill */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,32,0,128,170,0,160,170,128,170,170,144,170,250,144,0,255,148,0,175,164,0,170,165,0,10,170,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 6: f0 t1 r1 outline */
0,0,0,0,0,0,3,240,0,160,15,192,64,60,0,160,79,0,160,128,192,145,0,48,142,0,0,176,0,8,79,0,4,161,0,2,0,128,1,0,112,1,0,47,242,1,240,46,0,15,240,0,0,12,0,0,0,0,0,0,0,0,0,0,
/* 7: f0 t1 r1 fill */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,32,0,128,170,0,160,170,128,170,170,144,170,250,144,0,255,148,0,175,164,0,170,165,0,10,170,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 8: f0 t2 r0 outline */
0,0,0,0,0,15,0,15,240,15,252,0,240,15,0,64,48,192,64,64,56,64,128,4,161,0,2,174,0,1,144,0,1,143,0,2,177,0,14,64,143,240,64,112,44,0,47,240,1,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 9: f0 t2 r0 fill */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,42,128,0,170,148,128,170,148,138,175,149,170,255,170,170,250,168,160,170,160,0,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 10: f0 t2 r1 outline */
0,0,0,0,0,0,0,15,192,3,252,0,0,15,0,0,48,192,160,64,56,64,128,4,161,0,2,174,0,1,144,0,1,143,0,2,177,0,14,64,143,240,160,112,44,0,47,240,1,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 11: f0 t2 r1 fill */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,0,0,42,128,0,170,148,128,170,148,138,175,149,170,255,170,170,250,168,160,170,160,0,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 12: f1 t0 r0 outline */
0,0,0,0,0,0,0,0,0,255,255,255,0,48,2,0,252,2,3,2,2,12,1,5,16,0,133,32,0,121,64,0,1,128,0,253,128,0,130,64,1,2,127,254,0,4,4,0,63,255,128,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 13: f1 t0 r0 fill */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,168,0,2,170,2,6,170,2,21,170,170,22,255,170,86,255,170,170,170,0,42,170,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 14: f1 t0 r1 outline */
0,0,0,0,0,0,0,0,0,3,255,192,0,48,0,0,252,5,3,2,2,12,1,5,16,0,133,32,0,121,64,0,1,128,0,253,128,0,130,64,1,5,127,254,0,4,4,0,63,255,128,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 15: f1 t0 r1 fill */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,168,0,2,170,2,6,170,2,21,170,170,22,255,170,86,255,170,170,170,0,42,170,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 16: f1 t1 r0 outline */
0,0,0,0,0,15,0,15,242,15,240,2,240,60,2,0,242,5,3,1,5,12,0,137,0,0,113,16,0,13,32,0,242,64,0,130,128,1,0,128,14,0,79,244,0,116,15,128,15,240,0,48,0,0,0,0,0,0,0,0,0,0,0,0,
/* 17: f1 t1 r0 fill */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,2,0,170,2,2,170,10,6,170,170,5,175,170,22,255,0,22,250,0,90,170,0,170,160,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 18: f1 t1 r1 outline */
0,0,0,0,0,0,0,15,192,3,240,5,0,60,2,0,242,5,3,1,5,12,0,137,0,0,113,16,0,13,32,0,242,64,0,133,128,1,0,128,14,0,79,244,0,116,15,128,15,240,0,48,0,0,0,0,0,0,0,0,0,0,0,0,
/* 19: f1 t1 r1 fill */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,2,0,170,2,2,170,10,6,170,170,5,175,170,22,255,0,22,250,0,90,170,0,170,160,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 20: f1 t2 r0 outline */
0,0,0,240,0,0,15,240,0,0,63,240,0,240,15,3,12,2,28,2,2,32,1,2,64,0,133,128,0,117,128,0,9,64,0,241,112,0,141,15,241,2,52,14,2,15,244,0,0,15,128,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 21: f1 t2 r0 fill */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,160,0,2,168,0,22,170,0,21,170,2,86,250,162,166,255,170,42,175,170,10,170,10,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 22: f1 t2 r1 outline */
0,0,0,0,0,0,3,240,0,0,63,192,0,240,0,3,12,0,28,2,5,32,1,2,64,0,133,128,0,117,128,0,9,64,0,241,112,0,141,15,241,2,52,14,5,15,244,0,0,15,128,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 23: f1 t2 r1 fill */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,160,0,2,168,0,22,170,0,21,170,2,86,250,162,166,255,170,42,175,170,10,170,10,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 24: front r0 outline */
0,0,0,0,0,0,0,0,0,63,255,252,0,24,0,0,255,0,1,0,128,2,0,64,4,0,32,4,0,32,4,0,32,4,0,32,2,0,64,1,255,128,0,129,0,1,129,128,3,129,192,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 25: front r0 fill */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,170,0,1,85,64,1,85,64,1,85,64,2,85,64,3,255,192,2,170,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 26: front r1 outline */
0,0,0,0,0,0,0,0,0,0,255,0,0,24,0,0,255,0,1,0,128,2,0,64,4,0,32,4,0,32,4,0,32,4,0,32,2,0,64,1,255,128,0,129,0,1,129,128,3,129,192,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 27: front r1 fill */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,170,0,1,85,64,1,85,64,1,85,64,2,85,64,3,255,192,2,170,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 28: SP_SHADOW_BIG */
10,170,160,21,85,84,10,170,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 29: SP_SHADOW_SMALL */
0,170,0,1,85,64,0,170,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 30: SP_BIRD */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,0,96,14,1,192,3,135,0,0,252,0,0,120,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 31: SP_BIRD2 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,0,7,135,128,28,0,224,48,0,48,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 32: SP_BALLOON */
3,235,192,14,170,176,57,186,236,38,186,232,230,186,235,234,186,235,234,186,235,42,186,232,58,186,236,14,186,224,3,170,192,0,195,0,0,195,0,0,195,0,0,255,0,0,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 33: SP_JET_L */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,160,5,170,168,170,170,171,43,250,168,0,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 34: SP_JET_L2 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,160,5,170,168,170,170,175,43,250,168,0,160,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 35: SP_JET_R */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,10,0,0,42,170,80,234,170,170,42,175,232,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 36: SP_JET_R2 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,0,10,0,0,42,170,80,250,170,170,42,175,232,0,10,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 37: SP_BOOM */
0,0,0,0,0,0,0,0,0,0,12,0,0,12,0,0,63,0,0,60,0,0,63,192,0,235,192,0,234,64,3,235,192,3,234,192,0,235,0,0,255,192,0,63,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 38: SP_BOOM2 */
0,0,0,0,7,0,0,48,0,0,51,0,15,243,0,12,251,192,15,171,192,15,235,240,31,235,240,15,171,208,19,234,192,14,170,188,15,234,240,3,238,240,7,171,240,4,47,192,0,127,0,4,28,0,0,1,0,0,0,0,0,192,0,0,
/* 39: SP_BOOM3 */
0,76,0,3,115,0,0,255,0,0,255,240,7,239,240,15,235,240,15,235,195,62,170,240,254,170,188,254,170,252,30,170,244,254,170,252,14,170,240,15,170,204,63,251,252,15,171,252,15,255,192,15,255,240,4,63,208,3,192,0,12,77,0,0,
/* 40: SP_BLANK */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 41: SP_FIRE */
0,0,0,0,0,0,0,0,0,0,60,0,0,60,0,0,63,0,0,63,0,3,63,0,3,235,48,51,234,240,51,234,252,62,170,236,62,170,172,58,170,172,58,170,172,58,170,172,58,170,172,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 42: SP_FIRE2 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,0,0,255,0,48,255,240,63,250,252,63,170,252,58,170,172,58,170,172,58,170,172,58,170,172,58,170,172,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 43: SP_FIRE_S */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,0,12,0,3,12,0,3,60,0,14,251,12,14,235,204,14,170,204,58,170,188,58,170,188,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 44: SP_FIRE_S2 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,3,3,0,3,207,0,51,207,0,62,186,240,62,186,240,58,170,172,58,170,172,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 45: SP_SPRAY */
0,64,64,1,1,0,0,4,0,0,16,0,0,64,128,1,2,0,0,8,0,0,32,0,0,128,64,2,1,0,0,4,0,0,16,0,4,64,96,1,1,0,0,4,0,0,16,0,8,64,144,1,2,0,0,8,0,0,32,0,4,128,80,0,
/* 46: SP_SPRAY2 */
0,16,0,0,64,128,1,2,0,0,8,0,0,32,0,0,128,64,2,1,0,0,4,0,0,16,0,0,64,64,1,1,0,4,4,16,0,16,0,0,64,128,1,2,0,4,8,32,0,32,0,0,128,64,2,1,0,8,4,16,0,16,0,0,
/* 47: SP_STEAM */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16,0,0,97,128,2,160,64,10,32,96,5,42,160,6,84,96,9,66,80,0,101,160,9,138,32,6,17,144,2,2,128,2,130,128,0,16,0,0,0,0,0,0,0,0,
/* 48: SP_STEAM2 */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,149,128,2,133,128,0,166,128,2,74,128,10,162,32,2,154,16,1,74,96,2,166,32,10,96,160,1,41,64,1,34,0,0,8,0,0,0,0,0,0,0,0,
};

#endif

+ 23
- 0
projects/chopper/src/gfx.inc 파일 보기

@@ -0,0 +1,23 @@
; Generated by tools/gen_gfx.py - do not edit by hand. Sprite block numbers.
SPR_BASE = 16 ; block of sprite 0: ($8400 - $8000) / 64
SP_SHADOW_BIG = 28
SP_SHADOW_SMALL = 29
SP_BIRD = 30
SP_BIRD2 = 31
SP_BALLOON = 32
SP_JET_L = 33
SP_JET_L2 = 34
SP_JET_R = 35
SP_JET_R2 = 36
SP_BOOM = 37
SP_BOOM2 = 38
SP_BOOM3 = 39
SP_BLANK = 40
SP_FIRE = 41
SP_FIRE2 = 42
SP_FIRE_S = 43
SP_FIRE_S2 = 44
SP_SPRAY = 45
SP_SPRAY2 = 46
SP_STEAM = 47
SP_STEAM2 = 48

+ 17
- 0
projects/chopper/src/hazards.inc 파일 보기

@@ -0,0 +1,17 @@
; hazards.inc - shared by hazards.s (main.c mirrors these as #defines)
.include "gfx.inc"

MAXH = 8 ; hazard slots (mux.s MAXV = MAXH + 1 for the spray)
HZ_NONE = 0
HZ_BIRD = 1
HZ_BALLOON = 2
HZ_JET = 3
HZ_FIRE = 4
HZ_STEAM = 5
HZ_LOST = 6 ; a fire that left the screen burning (main.c clears it)

FIRE_HP = 48 ; frames of water a fire needs
SPRAY_HALF_W = 12 ; water hits fires within this many px sideways
SPRAY_REACH = 40 ; ... and with their top this far below the chopper's
STEAM_TIME = 48
COLOR_STEAM = 15 ; light grey

+ 329
- 0
projects/chopper/src/hazards.s 파일 보기

@@ -0,0 +1,329 @@
; hazards.s - per-frame update of the things the chopper has to avoid.
;
; Each hazard has a screen X with 1/256 px precision (xf, xlo, xhi). Every frame
; it moves by its own speed minus the ground speed, so it travels with the
; landscape, and it is dropped once it leaves the screen. Its Y follows a wave
; for birds and balloons. A box test against the chopper sets hz_hit, and the
; hazard is handed to the multiplexer as a virtual sprite (v_*, mux.s).
; Spawning and what a hit does are game rules: they live in main.c.
;
; Fires are hazards too: own speed 0, so they ride exactly with the ground
; layer (main.c starts them in step with scroll.s's sub-pixel position). Water
; from the chopper (spray_*) wears a fire's hp down; at 0 it turns into a puff
; of steam (counted in hz_saved). A fire that leaves the screen still burning
; becomes HZ_LOST for main.c to mark its tree as burnt.

.export _haz_update, _world_d, _hit_on, _hit_xlo, _hit_xhi, _hit_y, _hz_hit
.export _hz_type, _hz_xf, _hz_xlo, _hz_xhi, _hz_vx, _hz_y, _hz_base, _hz_t, _hz_col
.export _hz_hp, _hz_saved, _hz_lostany, _spray_on, _spray_xlo, _spray_xhi, _spray_y
.export _fire_near
.import _v_on, _v_y, _v_x, _v_flags, _v_ptr, _v_col
.importzp tmp1, tmp2, tmp3, tmp4, ptr1

.include "hazards.inc"

.segment "BSS"
_hz_type: .res MAXH ; HZ_NONE, HZ_BIRD, HZ_BALLOON, HZ_JET
_hz_xf: .res MAXH
_hz_xlo: .res MAXH
_hz_xhi: .res MAXH
_hz_vx: .res MAXH ; own speed, signed 1/16 px per frame
_hz_y: .res MAXH
_hz_base: .res MAXH
_hz_t: .res MAXH
_hz_col: .res MAXH
_world_d: .res 1 ; ground speed this frame, signed 1/16 px
_hit_on: .res 1 ; non-zero: test collisions
_hit_xlo: .res 1 ; chopper sprite position
_hit_xhi: .res 1
_hit_y: .res 1
_hz_hit: .res 1 ; 0, or 1 + index of a hazard touching the chopper
_hz_hp: .res MAXH ; fire: water still needed (frames of spray)
_hz_saved: .res 1 ; fires put out this frame
_hz_lostany: .res 1 ; non-zero: some slot became HZ_LOST this frame
_spray_on: .res 1 ; non-zero: water is falling from the chopper
_spray_xlo: .res 1 ; chopper sprite position
_spray_xhi: .res 1
_spray_y: .res 1
_fire_near: .res 1 ; a fire is in reach of the water (for the demo pilot)

.segment "RODATA"
; per type (index 0 unused): collision half-widths/heights (chopper + hazard),
; multicolor flag for v_flags
; none bird balloon jet fire steam lost
half_w: .byte 0, 15, 16, 18, 0, 0, 0 ; 0 = never hits the chopper
half_h: .byte 0, 7, 12, 6, 0, 0, 0
mc_flag: .byte 0, 0, 2, 2, 2, 2, 0
; 32-step waves
wave_bird: .byte 0,1,2,3,4,5,5,6,6,6,5,5,4,3,2,1
.byte 0,<-1,<-2,<-3,<-4,<-5,<-5,<-6,<-6,<-6,<-5,<-5,<-4,<-3,<-2,<-1
wave_bal: .byte 0,2,4,5,7,8,9,10,10,10,9,8,7,5,4,2
.byte 0,<-2,<-4,<-5,<-7,<-8,<-9,<-10,<-10,<-10,<-9,<-8,<-7,<-5,<-4,<-2

.segment "CODE"

; void haz_update(void);
_haz_update:
lda #0
sta _hz_hit
sta _hz_saved
sta _hz_lostany
sta _fire_near
ldx #0
@loop: lda #0
sta _v_on,x ; shown only if it reaches @emit
lda _hz_type,x
beq :+
cmp #HZ_LOST ; waiting for main.c
bne :++
: jmp @next

: ; ---- move: d = own speed - ground speed, as 1/16 px; add d*16/256 px
lda _hz_vx,x
sec
sbc _world_d
sta tmp1
asl a
asl a
asl a
asl a
sta tmp2 ; low byte of d*16
lda tmp1
cmp #$80
ror a
cmp #$80
ror a
cmp #$80
ror a
cmp #$80
ror a
sta tmp3 ; high byte
ldy #0
cmp #$80
bcc :+
dey
: sty tmp4
clc
lda _hz_xf,x
adc tmp2
sta _hz_xf,x
lda _hz_xlo,x
adc tmp3
sta _hz_xlo,x
lda _hz_xhi,x
adc tmp4
sta _hz_xhi,x

; ---- keep while 0 <= x < 376 (hazards spawn just off either edge)
beq @inside
cmp #1
bne @kill
lda _hz_xlo,x
cmp #120
bcc @inside
@kill: lda _hz_type,x
cmp #HZ_FIRE
bne :+
lda #HZ_LOST ; a fire got away: main.c burns its tree
sta _hz_type,x
sta _hz_lostany
jmp @next
: lda #HZ_NONE
sta _hz_type,x
jmp @next

@inside:
inc _hz_t,x
lda _hz_type,x
cmp #HZ_BIRD
bne @notbird
lda _hz_t,x ; bird: quick wave, flap every 4 frames
and #31
tay
lda wave_bird,y
clc
adc _hz_base,x
sta _hz_y,x
lda _hz_t,x
lsr a
lsr a
and #1
clc
adc #SPR_BASE + SP_BIRD
sta ptr1
jmp @hit
@notbird:
cmp #HZ_FIRE
bne :+
jmp @fire
: cmp #HZ_STEAM
bne :+
jmp @steam
: cmp #HZ_BALLOON
bne @jet
lda _hz_t,x ; balloon: slow bob
lsr a
lsr a
and #31
tay
lda wave_bal,y
clc
adc _hz_base,x
sta _hz_y,x
lda #SPR_BASE + SP_BALLOON
sta ptr1
jmp @hit
@jet: lda _hz_base,x ; jet: straight line, flickering exhaust
sta _hz_y,x
lda _hz_t,x
lsr a
and #1
ldy _hz_vx,x
bmi :+
clc
adc #SP_JET_R - SP_JET_L
: clc
adc #SPR_BASE + SP_JET_L
sta ptr1

jmp @hit

@fire: lda _hz_base,x ; fire: fixed on its tree, flickering
sta _hz_y,x
lda _hz_t,x
lsr a
lsr a
and #1
ldy _hz_hp,x
cpy #FIRE_HP / 2
bcs :+
clc
adc #SP_FIRE_S - SP_FIRE ; half put out: smaller flames
: clc
adc #SPR_BASE + SP_FIRE
sta ptr1
lda _hz_xlo,x ; in reach: chopper right above, close enough
sec
sbc _spray_xlo
sta tmp2
lda _hz_xhi,x
sbc _spray_xhi
beq :+
cmp #$FF
bne @emit_j
lda tmp2
beq @emit_j
eor #$FF
clc
adc #1
sta tmp2
: lda tmp2
cmp #SPRAY_HALF_W
bcs @emit_j
lda _hz_y,x ; fire top must be 0..SPRAY_REACH below the chopper top
sec
sbc _spray_y
bcc @emit_j
cmp #SPRAY_REACH
bcs @emit_j
inc _fire_near
lda _spray_on
beq @emit_j
dec _hz_hp,x
bne @emit_j
lda #HZ_STEAM ; out! a puff of steam rises from the tree
sta _hz_type,x
lda #0
sta _hz_t,x
lda #COLOR_STEAM
sta _hz_col,x
inc _hz_saved
@emit_j:
jmp @emit

@steam: lda _hz_t,x ; steam: rises and fades out
cmp #STEAM_TIME
bcc :+
lda #HZ_NONE
sta _hz_type,x
jmp @next
: lsr a
sta tmp1
lda _hz_base,x
sec
sbc tmp1
sta _hz_y,x
lda _hz_t,x
lsr a
lsr a
lsr a
and #1
clc
adc #SPR_BASE + SP_STEAM
sta ptr1
jmp @emit

; ---- collision box test against the chopper
@hit: lda _hit_on
beq @emit
lda _hz_xlo,x
sec
sbc _hit_xlo
sta tmp2
lda _hz_xhi,x
sbc _hit_xhi
beq @dxok ; 0..255 to the right
cmp #$FF
bne @emit ; far away
lda tmp2
beq @emit ; exactly -256
eor #$FF
clc
adc #1
sta tmp2 ; |dx|
@dxok: ldy _hz_type,x
lda tmp2
cmp half_w,y
bcs @emit
lda _hz_y,x
sec
sbc _hit_y
bcs :+
eor #$FF
adc #1 ; carry is clear: two's complement
: cmp half_h,y
bcs @emit
lda _hz_hit
bne @emit
inx
stx _hz_hit ; 1 + index
dex

; ---- hand it to the multiplexer
@emit: txa ; multiplexer slot = hazard slot
tay
lda #1
sta _v_on,y
lda _hz_y,x
sta _v_y,y
lda _hz_xlo,x
sta _v_x,y
lda _hz_type,x
sta tmp1
lda _hz_xhi,x
and #1
stx tmp2
ldx tmp1
ora mc_flag,x
ldx tmp2
sta _v_flags,y
lda ptr1
sta _v_ptr,y
lda _hz_col,x
sta _v_col,y

@next: inx
cpx #MAXH
bcs :+
jmp @loop
: rts

+ 1108
- 0
projects/chopper/src/main.c
파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
파일 보기


+ 480
- 0
projects/chopper/src/mux.s 파일 보기

@@ -0,0 +1,480 @@
; mux.s - one raster IRQ scheduler for the parallax band splits AND a sprite
; multiplexer (PAL).
;
; Hardware sprites 0-2 are the helicopter (outline, fill, shadow) and are set
; once per frame at line 251. Sprites 3-7 are shared by up to MAXV "virtual"
; hazard sprites: after a hardware sprite has finished drawing one hazard, the
; IRQ re-points it at another hazard lower down the screen.
;
; Virtual sprites live in fixed slots (v_on[slot] = shown this frame): slots
; 0-9 are the hazards, slot 10 the water spray. Each frame mux_build sorts the
; active slots by Y. The order is kept from frame to frame, and things move
; only a little between frames, so the insertion sort is nearly free. In Y
; order, the hardware sprite that frees up first is always the one used five
; sprites earlier, so sprites are handed out round-robin. Each re-use becomes
; an event, merged with the band splits into one list sorted by raster line,
; which the IRQ walks. Lists are double buffered: the IRQ swaps to the new one
; at line 251, so a half-built list is never shown.
;
; Band splits have windows of rows that never change (see scroll.s), so a split
; delayed a line or two by a sprite event leaves no visible seam:
; mountains: line 90 (rows 4-5 are always sky, lines 83-98)
; hills: line 164 (row 14 is always solid rock, lines 163-170)
; status: line 233 (last two lines of row 22 are solid black)
; Hazards never go below line ~212, so no sprite event lands near the status bar.

.export _irq_init, _irq_frame, _xs_clouds, _xs_mtns, _xs_hills
.export _mux_build, _mux_shown, _mux_dropped
.export _v_on, _v_y, _v_x, _v_flags, _v_ptr, _v_col
.export _hs_x, _hs_msb, _hs_y, _hs_p0, _hs_p1, _hs_p2, _hs_en
.importzp tmp1, tmp2, tmp3, tmp4

MAXV = 9 ; virtual sprites: 8 hazards + the water spray
EVB = 16 ; events per list buffer: MAXV sprites + 3 bands + end
HWN = 5 ; hardware sprites 3-7
SPRPTR = $83F8 ; screen at $8000
SHADOW_Y = 220

K_SPR = 0
K_MTNS = 1
K_HILLS = 2
K_HUD = 3
K_TOP = 4

LINE_TOP = 251
LINE_MTNS = 90
LINE_HILLS = 164
LINE_HUD = 233

SKY = 14
MC_ON = $10

.segment "DATA"
_irq_frame: .byte 0
_xs_clouds: .byte MC_ON | 7
_xs_mtns: .byte MC_ON | 7
_xs_hills: .byte MC_ON | 7
front: .byte EVB ; list the IRQ plays
back: .byte 0 ; list mux_build writes

.segment "BSS"
; virtual sprites, one slot each, filled by the game every frame
_v_on: .res MAXV ; non-zero: show this slot
_v_y: .res MAXV
_v_x: .res MAXV ; X low byte
_v_flags: .res MAXV ; bit 0 = X bit 8, bit 1 = multicolor
_v_ptr: .res MAXV
_v_col: .res MAXV
; helicopter shadow registers, applied at line 251
_hs_x: .res 1
_hs_msb: .res 1 ; $D010 bits 0-2
_hs_y: .res 1
_hs_p0: .res 1
_hs_p1: .res 1
_hs_p2: .res 1
_hs_en: .res 1 ; $D015 bits 0-2
; statistics of the last build
_mux_shown: .res 1
_mux_dropped: .res 1

ready: .res 1 ; back list is complete
irq_tmp: .res 1 ; the IRQ's own scratch byte
cur: .res 1 ; index of the next event
order: .res MAXV ; active slots in Y order, kept between frames
ordn: .res 1
inlist: .res MAXV ; slot is in order[]
ring: .res 1 ; next hardware sprite to hand out
hwfree: .res HWN ; raster line each hardware sprite is free (0 = unused)
hwen: .res 1
bandi: .res 1
evw: .res 1
; event lists (two buffers of EVB)
ev_line: .res 2*EVB
ev_kind: .res 2*EVB
ev_hw: .res 2*EVB
ev_y: .res 2*EVB
ev_x: .res 2*EVB
ev_flags: .res 2*EVB
ev_ptr: .res 2*EVB
ev_col: .res 2*EVB
ev_en: .res 2*EVB ; only [buffer base] used: sprites 3-7 enable bits

.segment "RODATA"
band_line: .byte LINE_MTNS, LINE_HILLS, LINE_HUD
band_kind: .byte K_MTNS, K_HILLS, K_HUD
hw_bit: .byte $08, $10, $20, $40, $80
hw_clr: .byte $F7, $EF, $DF, $BF, $7F

.segment "CODE"

; ---------------------------------------------------------------------------
; void irq_init(void);
_irq_init:
sei
lda #$7F
sta $DC0D ; no CIA timer IRQs
lda $DC0D
jsr _mux_build ; v_on all 0: just the band splits
jsr swap
ldx front ; start at this list's end-of-frame (line 251) event
: lda ev_kind,x
cmp #K_TOP
beq :+
inx
bne :-
: stx cur
lda #<irq ; hardware vectors in the RAM under the Kernal:
sta $FFFE ; the game makes no Kernal calls once running,
lda #>irq ; and skipping the Kernal's IRQ entry and exit
sta $FFFF ; saves ~30 cycles on each of ~14 IRQs a frame
lda #<nmi
sta $FFFA
lda #>nmi
sta $FFFB
lda #$35 ; RAM at $A000-$BFFF and $E000-$FFFF, I/O stays
sta $01
lda $D011
and #$7F
sta $D011
lda #LINE_TOP
sta $D012
lda #1
sta $D01A
sta $D019
cli
rts

swap: lda ready
beq :+
lda front
ldy back
sty front
sta back
lda #0
sta ready
: rts

; ---------------------------------------------------------------------------
; void mux_build(void); - build the next frame's event list from the v_* slots.
_mux_build:
lda #0
sta ready ; the IRQ must not swap to a half-built list
sta _mux_shown
sta _mux_dropped
sta hwen
sta bandi
sta ring
ldx #HWN-1
: sta hwfree,x
dex
bpl :-

; 1. drop slots that are no longer shown, keeping the old order
ldx #0
ldy #0
@keep: cpx ordn
bcs @kept
lda order,x
stx tmp2
tax
lda _v_on,x
beq @gone
txa
sta order,y
iny
bne @knext ; always
@gone: lda #0
sta inlist,x
@knext: ldx tmp2
inx
bne @keep
@kept: sty ordn

; 2. append slots that just appeared
ldx #0
@add: lda _v_on,x
beq @anext
lda inlist,x
bne @anext
lda #1
sta inlist,x
txa
ldy ordn
sta order,y
inc ordn
@anext: inx
cpx #MAXV
bne @add

; 3. insertion sort by Y (nearly sorted already)
ldx #1
@outer: cpx ordn
bcs @sorted
lda order,x
sta tmp1 ; key slot
tay
lda _v_y,y
sta tmp2 ; key y
txa
tay ; Y = j
@inner: lda order-1,y
sta tmp3
stx tmp4
tax
lda _v_y,x
ldx tmp4
cmp tmp2
bcc @place
beq @place
lda tmp3
sta order,y
dey
bne @inner
@place: lda tmp1
sta order,y
inx
bne @outer

@sorted:
lda back
sta evw
ldx #0 ; k
@vloop: cpx ordn
bcc :+
jmp @bands
: stx tmp3
lda order,x
sta tmp4 ; slot

ldy ring ; the hardware sprite that frees up first
sty tmp2
lda hwfree,y
sta tmp1
beq @fits ; not used yet this frame: set at the top
ldx tmp4 ; re-use: set up at least 3 lines before it starts
clc
adc #3
cmp _v_y,x
bcc @fits
beq @fits
inc _mux_dropped
jmp @vnext

@fits: ; first emit band splits that come before this event
lda tmp1
beq @emit
@bpend: ldy bandi
cpy #3
bcs @emit
lda band_line,y
cmp tmp1
bcs @emit ; band line > event line: later
jsr emit_band
jmp @bpend

@emit: ldy evw
lda tmp1
sta ev_line,y
lda #K_SPR
sta ev_kind,y
lda tmp2
sta ev_hw,y
ldx tmp4
lda _v_y,x
sta ev_y,y
clc
adc #22 ; free again after 21 lines
ldx tmp2
sta hwfree,x
lda hw_bit,x
ora hwen
sta hwen
inx ; next in the ring
cpx #HWN
bne :+
ldx #0
: stx ring
ldx tmp4
lda _v_x,x
sta ev_x,y
lda _v_flags,x
sta ev_flags,y
lda _v_ptr,x
sta ev_ptr,y
lda _v_col,x
sta ev_col,y
inc evw
inc _mux_shown

@vnext: ldx tmp3
inx
jmp @vloop

@bands: ldy bandi ; remaining band splits, then end of frame
cpy #3
bcs @end
jsr emit_band
jmp @bands
@end: ldy evw
lda #LINE_TOP
sta ev_line,y
lda #K_TOP
sta ev_kind,y
ldy back
lda hwen
sta ev_en,y
lda #1
sta ready
rts

emit_band: ; Y = bandi
lda band_line,y
ldx band_kind,y
ldy evw
sta ev_line,y
txa
sta ev_kind,y
inc evw
inc bandi
rts

; ---------------------------------------------------------------------------
; The IRQ: run every event that is due, then arm the raster compare for the next.
nmi: rti ; RESTORE key: ignored

irq: pha
txa
pha
tya
pha
lda #1
sta $D019
@next: ldx cur
lda ev_kind,x
bne @notspr
jsr spr_setup
jmp @adv
@notspr:
cmp #K_MTNS
bne :+
lda _xs_mtns
sta $D016
lda #4 ; purple: lit mountain slopes
sta $D023
jmp @adv
: cmp #K_HILLS
bne :+
lda _xs_hills
sta $D016
lda #6 ; blue plain behind the hills
sta $D021
lda #13 ; light green
sta $D022
lda #9 ; brown
sta $D023
jmp @adv
: cmp #K_HUD
bne @top
lda #MC_ON
sta $D016
lda #0
sta $D021
jmp @adv

@top: jsr swap ; line 251: start the next frame
lda _hs_x
sta $D000
sta $D002
sta $D004
lda _hs_y
sta $D001
sta $D003
lda #SHADOW_Y
sta $D005
lda _hs_p0
sta SPRPTR
lda _hs_p1
sta SPRPTR+1
lda _hs_p2
sta SPRPTR+2
lda _hs_msb
sta $D010
lda #$02 ; helicopter fill is multicolor
sta $D01C
ldx front
lda ev_en,x
ora _hs_en
sta $D015
lda _xs_clouds
sta $D016
lda #SKY
sta $D021
lda #1 ; white
sta $D022
lda #15 ; light grey
sta $D023
inc _irq_frame
ldx front ; first event of the new list
stx cur
lda ev_line,x
sta $D012
jmp irq_exit

@adv: inx
stx cur
lda ev_line,x
bit $D011 ; raster >= 256: nothing in this list is due yet
bmi @arm
ldy $D012
cpy #LINE_TOP
bcs @arm
sta irq_tmp ; never cc65's tmp1-4: the IRQ can land in the
tya ; middle of code that is using them
clc
adc #2
cmp irq_tmp ; raster + 2 >= event line: do it now
bcc :+
jmp @next
: lda irq_tmp
@arm: sta $D012
jmp irq_exit

irq_exit:
pla
tay
pla
tax
pla
rti

; X = event index (preserved)
spr_setup:
ldy ev_hw,x
lda ev_ptr,x
sta SPRPTR+3,y
lda ev_col,x
sta $D027+3,y
lda ev_flags,x
lsr a ; C = X bit 8
lda $D010
and hw_clr,y
bcc :+
ora hw_bit,y
: sta $D010
lda ev_flags,x
and #2
beq :+
lda $D01C
ora hw_bit,y
bne :++
: lda $D01C
and hw_clr,y
: sta $D01C
tya
asl a
tay
lda ev_x,x
sta $D006,y
lda ev_y,x
sta $D007,y
rts

+ 205
- 0
projects/chopper/src/scroll.s 파일 보기

@@ -0,0 +1,205 @@
; scroll.s - the time-critical part of the parallax engine.
;
; Three layers (0 clouds, 1 mountains, 2 hills). Each has a 24-bit position:
; px (16-bit pixels) + frac (1/256 px). The C code moves a layer with
; layer_step(); when the layer crosses a character boundary it builds the new
; column into nb_<band>, and apply_scroll() (called right after line 251)
; shifts the band one character and drops the column in.
;
; Only rows that can change are shifted. The generators guarantee:
; clouds rows 0-3 vary, row 4 always sky
; mountains rows 6-13 vary, row 5 always sky, row 14 always solid rock
; hills rows 18-22 vary, rows 15-17 always sky (hills and trees are low)
; main.c's self-test checks these invariants.

.export _layer_step, _apply_scroll, _move_d
.export _lay_px_lo, _lay_px_hi, _lay_frac, _lay_col_lo, _lay_col_hi
.export _lay_pend, _lay_xs
.export _nb_clouds, _nb_mtns, _nb_hills
.import _xs_clouds, _xs_mtns, _xs_hills
.importzp tmp1, tmp2, tmp3, tmp4

SCREEN = $8000
VIC_D016 = $D016

.segment "BSS"
_move_d: .res 1 ; signed step in 1/16 px, input to layer_step
_lay_px_lo: .res 3
_lay_px_hi: .res 3
_lay_frac: .res 3
_lay_col_lo:.res 3 ; world column at screen column 0 (12 bits)
_lay_col_hi:.res 3
_lay_pend: .res 3 ; coarse step for apply_scroll: 0, 1 (left), $FF (right)
_lay_xs: .res 3 ; $D016 value for the band
_nb_clouds: .res 5 ; incoming column, indexed by band row
_nb_mtns: .res 10
_nb_hills: .res 8

.segment "CODE"

; unsigned char __fastcall__ layer_step(unsigned char layer);
; Adds move_d/16 px to the layer. Returns (and stores in lay_pend) the coarse
; step: 0 none, 1 = contents move left, $FF = contents move right.
_layer_step:
tax
lda _move_d
sta tmp1
asl a
asl a
asl a
asl a
sta tmp2 ; low byte of move_d * 16
lda tmp1
cmp #$80
ror a
cmp #$80
ror a
cmp #$80
ror a
cmp #$80
ror a
sta tmp3 ; high byte (arithmetic move_d >> 4)
ldy #0
cmp #$80
bcc :+
dey
: sty tmp4 ; sign extension
clc
lda _lay_frac,x
adc tmp2
sta _lay_frac,x
lda _lay_px_lo,x
adc tmp3
sta _lay_px_lo,x
lda _lay_px_hi,x
adc tmp4
sta _lay_px_hi,x

lda _lay_px_lo,x ; $D016 = multicolor | (7 - (px & 7))
and #7
eor #$17
sta _lay_xs,x

lda _lay_px_hi,x ; new column = (px >> 3) & $0FFF
sta tmp2
lda _lay_px_lo,x
lsr tmp2
ror a
lsr tmp2
ror a
lsr tmp2
ror a
sta tmp1
lda tmp2
and #$0F
sta tmp2

lda tmp1 ; diff = new - old (mod 4096)
sec
sbc _lay_col_lo,x
sta tmp3
lda tmp2
sbc _lay_col_hi,x
and #$0F
sta tmp4
ora tmp3
beq @none
lda tmp4
bne @back
lda tmp3
cmp #1
bne @back
lda #1
bne @store
@back: lda #$FF
bne @store
@none: lda #0
@store: sta _lay_pend,x
lda tmp1
sta _lay_col_lo,x
lda tmp2
sta _lay_col_hi,x
lda _lay_pend,x
ldx #0
rts

; Shift rows [row0, row0+nrows) one character; store the new column from
; buf[boff..] at column 39 (left) or column 0 (right).
.macro SHIFT_L row0, nrows, buf, boff
ldx #0
:
.repeat nrows, I
lda SCREEN + (row0 + I) * 40 + 1, x
sta SCREEN + (row0 + I) * 40, x
.endrepeat
inx
cpx #39
bne :-
.repeat nrows, I
lda buf + boff + I
sta SCREEN + (row0 + I) * 40 + 39
.endrepeat
rts
.endmacro

.macro SHIFT_R row0, nrows, buf, boff
ldx #38
:
.repeat nrows, I
lda SCREEN + (row0 + I) * 40, x
sta SCREEN + (row0 + I) * 40 + 1, x
.endrepeat
dex
bpl :-
.repeat nrows, I
lda buf + boff + I
sta SCREEN + (row0 + I) * 40
.endrepeat
rts
.endmacro

clouds_l: SHIFT_L 0, 4, _nb_clouds, 0
clouds_r: SHIFT_R 0, 4, _nb_clouds, 0
mtns_l: SHIFT_L 6, 8, _nb_mtns, 1
mtns_r: SHIFT_R 6, 8, _nb_mtns, 1
hills_l: SHIFT_L 18, 5, _nb_hills, 3
hills_r: SHIFT_R 18, 5, _nb_hills, 3

; void apply_scroll(void); - call once per frame, right after line 251.
; Top band first; each band's $D016 value is published right after its shift,
; ahead of the raster IRQ that loads it.
_apply_scroll:
lda _lay_pend+0
beq @c
bmi :+
jsr clouds_l
jmp @c0
: jsr clouds_r
@c0: lda #0
sta _lay_pend+0
@c: lda _lay_xs+0
sta _xs_clouds
sta VIC_D016 ; clouds start at line 51: set it directly

lda _lay_pend+1
beq @m
bmi :+
jsr mtns_l
jmp @m0
: jsr mtns_r
@m0: lda #0
sta _lay_pend+1
@m: lda _lay_xs+1
sta _xs_mtns ; IRQ at line 89

lda _lay_pend+2
beq @h
bmi :+
jsr hills_l
jmp @h0
: jsr hills_r
@h0: lda #0
sta _lay_pend+2
@h: lda _lay_xs+2
sta _xs_hills ; IRQ at line 169
rts

+ 473
- 0
projects/chopper/tools/gen_gfx.py 파일 보기

@@ -0,0 +1,473 @@
#!/usr/bin/env python3
"""
gen_gfx.py - build src/gfx.h (sprites + landscape tiles) for the chopper game.

python projects/chopper/tools/gen_gfx.py

Sprites
Each helicopter pose is two sprites stacked at the same position:
* outline: hi-res, black (sprite 0, in front)
* fill: multicolor (sprite 1, behind) body = own colour,
window = $D025, stripe = $D026
Poses = facing (right, left) x tilt (level, nose-down, nose-up) x rotor (A, B)
+ front view (A, B) used while turning around.
Tilts are produced by shearing the level art; left-facing art is a mirror.

Tiles
Multicolor characters, 4 double-wide pixels x 8 rows:
'.' = 00 background ($D021) 'w' = 01 ($D022)
'g' = 10 ($D023) '#' = 11 colour RAM
"""
import os

W, H = 24, 21

# ---------------------------------------------------------------- helicopter art
# '#' outline 'b' body fill 'w' window 's' stripe ' ' empty
SIDE_BODY = [
"", # 0
"", # 1
"", # 2
"", # 3 rotor goes here
" ##", # 4 mast
" ######", # 5
" # #bbbbbb##", # 6
"#b# #bbbbbbbbb##", # 7
"#b# #bbbbbbbbbbww#", # 8
"#bb####bbbbbbbbbbwwww#", # 9
"#bbbbbbbssssssssbbwwww#", # 10
"#b######ssssssssbbbwwww#", # 11
" # #bbbbbbbbbbbbbbb#", # 12
" #bbbbbbbbbbbbb#", # 13
" ##############", # 14
" # #", # 15
" ###############", # 16 skid
]
ROTOR_A = {3: "########################"} # full blade, side on
ROTOR_B = {3: " ############"} # blade turned toward us
TAIL_A = {4: " #", 5: " #", 12: "", 13: " #"} # tail rotor vertical
TAIL_B = {8: "#b#"} # (drawn by body) - horizontal hint
TAIL_B_EXTRA = [(0, 5), (2, 5), (0, 13), (2, 13)]

FRONT_BODY = [
"", "", "", "",
" ##", # 4
" ########", # 5
" #bbbbbbbb#", # 6
" #wwwwwwwwww#", # 7
" #wwwwwwwwwwww#", # 8
" #wwwwwwwwwwww#", # 9
" #bwwwwwwwwwwb#", # 10
" #ssssssssssss#", # 11
" #bbbbbbbbbb#", # 12
" ##########", # 13
" # #", # 14
" ## ##", # 15
" ### ###", # 16
]
FRONT_ROTOR_A = {3: " ####################"}
FRONT_ROTOR_B = {3: " ########"}


def blank():
return [[" "] * W for _ in range(H)]


def stamp(grid, rows, only_hash=False):
for y, line in rows.items() if isinstance(rows, dict) else enumerate(rows):
for x, ch in enumerate(line):
if ch != " " and x < W:
grid[y][x] = ch


def side_pose(rotor):
g = blank()
stamp(g, SIDE_BODY)
if rotor == 0:
stamp(g, ROTOR_A)
stamp(g, TAIL_A)
else:
stamp(g, ROTOR_B)
for x, y in TAIL_B_EXTRA:
g[y][x] = "#"
return g


def front_pose(rotor):
g = blank()
stamp(g, FRONT_BODY)
stamp(g, FRONT_ROTOR_A if rotor == 0 else FRONT_ROTOR_B)
return g


def shear(g, sign):
"""sign=+1: nose (right side) down; sign=-1: nose up."""
out = blank()
for y in range(H):
for x in range(W):
if g[y][x] == " ":
continue
d = ((x - 12) // 8) if sign > 0 else ((11 - x) // 8)
ny = y + d
assert 0 <= ny < H, (x, y, ny)
out[ny][x] = g[y][x]
return out


def mirror(g):
return [list(reversed(r)) for r in g]


def outline_sprite(g):
data = []
for y in range(H):
bits = 0
for x in range(W):
bits = (bits << 1) | (1 if g[y][x] == "#" else 0)
data += [(bits >> 16) & 255, (bits >> 8) & 255, bits & 255]
return data + [0]


# multicolor sprite pair codes: 01=$D025 (window), 10=own colour (body), 11=$D026 (stripe)
MC_CODE = {"w": 1, "b": 2, "s": 3}


def fill_sprite(g):
data = []
for y in range(H):
bits = 0
for px in range(12):
a, b = g[y][2 * px], g[y][2 * px + 1]
cands = [c for c in (a, b) if c in MC_CODE]
if not cands:
# pair is outline/empty: fill under outline so no gaps show
code = 2 if (" " not in (a, b) and inside(g, y, 2 * px)) else 0
else:
code = MC_CODE[cands[0]]
bits = (bits << 2) | code
data += [(bits >> 16) & 255, (bits >> 8) & 255, bits & 255]
return data + [0]


def inside(g, y, x):
"""True if (x..x+1, y) is an outline pixel with fill on both sides horizontally."""
row = g[y]
left = any(c in MC_CODE for c in row[:x])
right = any(c in MC_CODE for c in row[x + 2:])
return left and right


def shadow_sprite(width):
data = []
for y in range(H):
bits = 0
if y < 3:
half = width // 2 - (2 if y != 1 else 0)
for x in range(W):
on = abs(x - 11.5) < half and ((x + y) & 1) == 0
bits = (bits << 1) | (1 if on else 0)
data += [(bits >> 16) & 255, (bits >> 8) & 255, bits & 255]
return data + [0]


sprites = [] # list of 64-byte blocks
names = []
for facing in range(2): # 0 right, 1 left
for tilt in range(3): # 0 level, 1 nose down, 2 nose up
for rotor in range(2):
g = side_pose(rotor)
if tilt == 1:
g = shear(g, +1)
elif tilt == 2:
g = shear(g, -1)
if facing == 1:
g = mirror(g)
sprites.append(outline_sprite(g))
sprites.append(fill_sprite(g))
names.append(f"f{facing} t{tilt} r{rotor}")
for rotor in range(2):
g = front_pose(rotor)
sprites.append(outline_sprite(g))
sprites.append(fill_sprite(g))
names.append(f"front r{rotor}")
sprites.append(shadow_sprite(20))
sprites.append(shadow_sprite(12))
assert len(sprites) == 30

# ---------------------------------------------------------------- hazards
# Hazards are single sprites. Hi-res art: '#' set. Multicolor art is drawn at
# 12 double-wide pixels: '.' 00, 'w' 01 ($D025 cyan), 'b' 10 own colour, 's' 11 ($D026 red).
def hires_sprite(rows):
data = []
for y in range(H):
line = rows[y] if y < len(rows) else ""
assert len(line) <= W, line
bits = 0
for x in range(W):
bits = (bits << 1) | (1 if x < len(line) and line[x] == "#" else 0)
data += [(bits >> 16) & 255, (bits >> 8) & 255, bits & 255]
return data + [0]


def mc_sprite(rows):
data = []
for y in range(H):
line = rows[y] if y < len(rows) else ""
assert len(line) <= 12, line
bits = 0
for x in range(12):
bits = (bits << 2) | ".wbs".index(line[x] if x < len(line) else ".")
data += [(bits >> 16) & 255, (bits >> 8) & 255, bits & 255]
return data + [0]


BIRD_UP = [""] * 6 + [
" ## ##",
" ### ###",
" ### ###",
" ######",
" ####",
]
BIRD_DOWN = [""] * 8 + [
" ######",
" #### ####",
" ### ###",
" ## ##",
]
BALLOON = [
"...ssbbss...",
"..sbbbbbbs..",
".sbwbsbbsbs.",
".bwbbsbbsbb.",
"sbwbbsbbsbbs",
"sbbbbsbbsbbs",
"sbbbbsbbsbbs",
".bbbbsbbsbb.",
".sbbbsbbsbs.",
"..sbbsbbsb..",
"...sbbbbs...",
"....s..s....",
"....s..s....",
"....s..s....",
"....ssss....",
"....ssss....",
]
JET_L = [""] * 7 + [
".........b..",
"........bb..",
"..wwbbbbbbb.",
"bbbbbbbbbbbs",
".bbsssbbbbb.",
"....bb......",
]
JET_L2 = JET_L[:10] + ["bbbbbbbbbbss"] + JET_L[11:]


def mirror12(rows):
return [r.ljust(12, ".")[::-1] for r in rows]


def explosion(radius, seed):
import random
rng = random.Random(seed)
rows = []
for y in range(H):
line = ""
for x in range(12):
dx, dy = (x - 5.5) * 2, (y - 10)
d = (dx * dx + dy * dy) ** 0.5 + rng.uniform(-1.5, 1.5)
if d < radius * 0.45:
line += "b" # yellow core
elif d < radius * 0.8:
line += "s" # red fire
elif d < radius and rng.random() < 0.5:
line += "w" if rng.random() < 0.3 else "s"
else:
line += "."
rows.append(line)
return rows


def flames(height, seed):
"""Flames over a tree canopy (rows up to 16): pointed tongues, red edge
('s') around a yellow core ('b') that sits low in the fire."""
import random
rng = random.Random(seed)
tops = []
for x in range(12):
centre = 1.0 - abs(x - 5.5) / 6.0 # taller in the middle
h = height * (0.35 + centre) + rng.uniform(-1.0, 1.0)
if rng.random() < 0.35:
h += rng.uniform(2, 4) # a tongue licking up
tops.append(max(0, min(15, int(round(h)))))
rows = ["." * 12 for _ in range(H)]
for x in range(1, 11):
for k in range(tops[x]):
y = 16 - k
edge = (k >= tops[x] - 2 or x in (1, 10) or tops[x - 1] <= k or tops[x + 1] <= k
or k > tops[x] * 0.6)
ch = "s" if edge else "b"
rows[y] = rows[y][:x] + ch + rows[y][x + 1:]
return rows


def spray(phase):
"""Water drops falling from the skids: cyan 'w' and white own colour 'b'."""
rows = []
for y in range(H):
line = ""
for x in range(12):
on = 3 <= x <= 8 and (x * 7 + y * 3 + phase * 5) % 4 == 0
wide = y > 10 and x in (2, 9) and (y + phase) % 4 == 0
line += ("b" if (x + y) % 3 == 0 else "w") if (on or wide) else "."
rows.append(line)
return rows


def steam(seed):
import random
rng = random.Random(seed)
rows = []
for y in range(H):
line = ""
for x in range(12):
d = ((x - 5.5) ** 2 / 20 + (y - 12) ** 2 / 40)
line += ("b" if rng.random() < 0.7 else "w") if d < 1 and rng.random() < 0.75 else "."
rows.append(line)
return rows


hazard_sprites = [
("SP_BIRD", hires_sprite(BIRD_UP)),
("SP_BIRD2", hires_sprite(BIRD_DOWN)),
("SP_BALLOON", mc_sprite(BALLOON)),
("SP_JET_L", mc_sprite(JET_L)),
("SP_JET_L2", mc_sprite(JET_L2)),
("SP_JET_R", mc_sprite(mirror12(JET_L))),
("SP_JET_R2", mc_sprite(mirror12(JET_L2))),
("SP_BOOM", mc_sprite(explosion(6, 1))),
("SP_BOOM2", mc_sprite(explosion(9, 2))),
("SP_BOOM3", mc_sprite(explosion(11, 3))),
("SP_BLANK", [0] * 64),
("SP_FIRE", mc_sprite(flames(8, 1))),
("SP_FIRE2", mc_sprite(flames(8, 2))),
("SP_FIRE_S", mc_sprite(flames(4, 3))),
("SP_FIRE_S2", mc_sprite(flames(4, 4))),
("SP_SPRAY", mc_sprite(spray(0))),
("SP_SPRAY2", mc_sprite(spray(1))),
("SP_STEAM", mc_sprite(steam(5))),
("SP_STEAM2", mc_sprite(steam(6))),
]
sprite_names = {28: "SP_SHADOW_BIG", 29: "SP_SHADOW_SMALL"}
for n, blk in hazard_sprites:
sprite_names[len(sprites)] = n
sprites.append(blk)

# ---------------------------------------------------------------- tiles
TILES = [
("T_CL_TL", ["....", "....", "....", "...w", "..ww", ".www", "wwww", "wwww"]),
("T_CL_TM1", ["....", ".ww.", "wwww", "wwww", "wwww", "wwww", "wwww", "wwww"]),
("T_CL_TM2", ["....", "....", "..ww", ".www", "wwww", "wwww", "wwww", "wwww"]),
("T_CL_TR", ["....", "....", "w...", "ww..", "www.", "www.", "wwww", "wwww"]),
("T_CL_BL", ["wwww", "wwww", ".www", ".wgg", "..gg", "....", "....", "...."]),
("T_CL_BM", ["wwww", "wwww", "wwww", "gwgw", "gggg", "....", "....", "...."]),
("T_CL_BR", ["wwww", "wwww", "www.", "ggw.", "gg..", "....", "....", "...."]),

("T_M_UP", ["...g", "...g", "..g#", "..g#", ".g##", ".g##", "g###", "g###"]),
("T_M_DN", ["#...", "#...", "##..", "##..", "###.", "###.", "####", "####"]),
("T_M_PEAK", [".g#.", ".g#.", ".g##", "g###", "g###", "g###", "g###", "####"]),
("T_M_UP_S", ["...w", "...w", "..ww", "..w#", ".ww#", ".w##", "g###", "g###"]),
("T_M_DN_S", ["w...", "w...", "ww..", "#w..", "#ww.", "##w.", "###.", "####"]),
("T_M_PK_S", [".ww.", ".ww.", ".www", "wwww", "ww#w", "w###", "g###", "g###"]),
("T_M_FL_S", ["wwww", "w#ww", "####", "##w#", "####", "####", "####", "####"]),
("T_M_SOLID", ["####"] * 8),
("T_M_SNOW", ["#w##", "####", "##w#", "####", "w###", "####", "####", "####"]),
("T_M_ROCK", ["####", "##g#", "#g##", "####", "####", "####", "####", "####"]),

("T_H_UP", ["...w", "..ww", "..w#", ".w##", ".w##", "w###", "w###", "####"]),
("T_H_DN", ["w...", "ww..", "#w..", "##w.", "##w.", "###w", "###w", "####"]),
("T_H_PEAK", ["....", ".ww.", "wwww", "w##w", "####", "#w##", "####", "####"]),
("T_H_FLAT", ["wwww", "####", "#w##", "####", "####", "##w#", "####", "####"]),
("T_H_SOLID", ["####", "#w##", "####", "####", "###w", "####", "####", "####"]),
("T_TREE_TOP", [".ww.", "w#w#", "ww##", "w###", "####", "####", ".##.", ".gg."]),
("T_TREE_TRUNK", [".gg.", ".gg.", ".gg.", ".gg.", ".gg.", ".gg.", ".gg.", "gggg"]),
("T_PINE_TOP", ["....", ".w#.", ".w#.", "ww##", "w###", ".w#.", "ww##", "w###"]),
("T_PINE_MID", [".w#.", "ww##", "w###", "####", ".w#.", "ww##", "w###", "####"]),
("T_PINE_TRUNK", [".gg.", ".gg.", ".gg.", ".gg.", ".gg.", ".gg.", ".gg.", "gggg"]),
("T_GRASS1", ["w.w.", "wwww", "#w#w", "####", "##w#", "####", "#w##", "####"]),
("T_GRASS2", [".w.w", "wwww", "w#w#", "####", "#w##", "####", "###w", "####"]),
("T_DIRT1", ["gggg", "g#gg", "gggg", "ggg#", "g#gg", "gggg", "####", "####"]),
("T_DIRT2", ["gggg", "gggg", "gg#g", "gggg", "#ggg", "gg#g", "####", "####"]),
("T_BURNT_TREE", ["g..g", ".g.g", "g.g.", ".gg.", "g.g.", ".gg.", ".gg.", ".gg."]),
("T_BURNT_PINE", ["..g.", ".gg.", "g.g.", ".gg.", ".ggg", "g.g.", ".gg.", ".gg."]),
]
PIX = {".": 0, "w": 1, "g": 2, "#": 3}


def tile_bytes(rows):
assert len(rows) == 8
out = []
for r in rows:
assert len(r) == 4, r
v = 0
for ch in r:
v = (v << 2) | PIX[ch]
out.append(v)
return out


FIRST_TILE = 64 # screen codes 64..127 are graphics in the ROM set; letters stay intact

here = os.path.dirname(os.path.abspath(__file__))
dst = os.path.join(here, "..", "src", "gfx.h")
with open(dst, "w", newline="\n") as f:
f.write("/* Generated by tools/gen_gfx.py - do not edit by hand. */\n")
f.write("#ifndef GFX_H\n#define GFX_H\n\n")
f.write(f"#define FIRST_TILE {FIRST_TILE}\n#define NUM_TILES {len(TILES)}\n")
for i, (n, _) in enumerate(TILES):
f.write(f"#define {n} {FIRST_TILE + i}\n")
f.write("\nstatic const unsigned char tile_data[NUM_TILES * 8] = {\n")
for n, rows in TILES:
f.write(" " + ",".join(f"0x{b:02X}" for b in tile_bytes(rows)) + f", /* {n} */\n")
f.write("};\n\n")
f.write(f"#define NUM_SPRITES {len(sprites)}\n")
f.write("/* blocks: [pose*2] outline, [pose*2+1] fill; poses 0-11 = facing*6+tilt*2+rotor,\n"
" 12-13 front view, then shadow big (28) and shadow small (29). */\n")
for i, n in sorted(sprite_names.items()):
f.write(f"#define {n} {i}\n")
f.write("static const unsigned char sprite_data[NUM_SPRITES * 64] = {\n")
for i, blk in enumerate(sprites):
label = names[i // 2] + (" outline" if i % 2 == 0 else " fill") if i < 28 else sprite_names[i]
f.write(f" /* {i}: {label} */\n " + ",".join(f"{b}" for b in blk) + ",\n")
f.write("};\n\n#endif\n")

with open(os.path.join(here, "..", "src", "gfx.inc"), "w", newline="\n") as f:
f.write("; Generated by tools/gen_gfx.py - do not edit by hand. Sprite block numbers.\n")
f.write("SPR_BASE = 16 ; block of sprite 0: ($8400 - $8000) / 64\n")
for i, n in sorted(sprite_names.items()):
f.write(f"{n} = {i}\n")

# quick visual dump for checking the art
if os.environ.get("SHOW"):
for i in range(0, 28, 2):
print(names[i // 2])
for y in range(H):
row = ""
for x in range(W):
o = (sprites[i][y * 3 + x // 8] >> (7 - x % 8)) & 1
fb = sprites[i + 1][y * 3 + (x // 2) // 4]
c = (fb >> (6 - 2 * ((x // 2) % 4))) & 3
row += "#" if o else ".wbs"[c] if c else " "
print(" |" + row + "|")
if os.environ.get("SHOW"):
for i in range(30, len(sprites)):
mc = sprite_names[i] not in ("SP_BIRD", "SP_BIRD2")
print(sprite_names[i])
for y in range(H):
b = sprites[i][y * 3:y * 3 + 3]
v = (b[0] << 16) | (b[1] << 8) | b[2]
if mc:
print(" |" + "".join(" wbs"[(v >> (22 - 2 * x)) & 3] * 2 for x in range(12)) + "|")
else:
print(" |" + "".join("#" if (v >> (23 - x)) & 1 else " " for x in range(24)) + "|")
print(f"wrote {dst}: {len(TILES)} tiles, {len(sprites)} sprites")

불러오는 중...
취소
저장

Powered by TurnKey Linux.