pouët.net

Streets of EORage by Otomata Labs [web]

; Streets of EORage
; 256 (244?) bytes intro for the Sega MegaDrive/Genesis
; at Multimatograf 2o26

; a little experiment based on discussions on the demoscene discord server
; about possibilities of MD sizecoding.
; best regards to leaq and superogue for the idea ;)

; i'm not sure if this is a successful experiment, as it seems to be randomized upon each run
; and if emulators are correct, this may not run under TMSS-equipped consoles (late MD1 and all MD2),
; at least if not launched from the flashcart like Everdrive.
; will try to fix it in the final version - hope there's enough bytes for that
; if it won't run anyway, feel free to treat it as a fantasy console entry =)

; ah yea, for running this for the physical ROM you may need to abuse ROM mirroring, e.g. connect only 
; address lines A0-A6 so data at 0x000..0x0FF gets mirrored at 0x100..0x1FF

; greets to my OTL groupmates for tips and suggestions, and to all sizecoders as well!

; --artemka 25.o4.2o26 (slpet 0 hours)
    
    org     0

;FULL_VECTOR_TABLE   set 1
;PAD_TO_512B         set 1
;UNLOCK_TMSS         set 1

    ; define "safe" vector table in the start if needed
    ifd FULL_VECTOR_TABLE
    dc.l    'SEGA'
    dc.l    start
    dcb.b   256-*               ; fill the rest with zeroes
    endif

    ; vector table, intermixed with ROM header (abuse ROM morroring)
    dc.l    'SEGA'              ; initial SP + part of "SEGA xxxxx" system type at $100 that TMSS checks for
    dc.l    start               ; initial PC

    ; other stuff overlaps with vectors
start:
    lea     $A10000,a4          ; a4 - peripheral start
    ifd     UNLOCK_TMSS
    ;move.b  1(a4),d0            ; check if TMSS present
    ;andi.b  #$0F,d0
    ;beq     .no_tmss
    move.l  sp,$4000(a4)        ; unlock VDP
    endif
.no_tmss:
    moveq   #0,d5               ; d5 = 0
    movea   d5,sp               ; init SP to top of RAM

    ; init VDP
    lea.l   $C00004,a6          ; a6 - VDP ctrl base
    lea.l   -4(a6),a5           ; a5 - VDP data base
    tst.w   0(a6)               ; clear stale VDP status
    move.l  #$80048144,0(a6)
    move.l  #$8B038C81,0(a6)
    move.l  #$82088401,0(a6)
    move.l  #$8d20853f,0(a6)
    move.l  #$9001853f,0(a6)
    move.l  #$8F02C000,0(a6)
    lea.l   cram_top,a1
    moveq   #(8-1),d1
.cram_fill:
    move.l  -(a1),(a5)
    dbra    d1,.cram_fill

    ; clear VRAM
    move.l  #$40000000,0(a6)
    move.w  #16-1,d1
;.tile_fill:
;    move.l  -(a1),(a5)
;    dbra    d1,.tile_fill

    move.w  #(65536/4)-1-0,d1
.vram_clr_loop:
    move.l  d5,(a5)
    dbra    d1,.vram_clr_loop

    ; play some audio crap yk

    ; request bus from the Z80, release reset from the YM
    moveq   #7,d7
    moveq   #1,d6
    move.b  d6,$1101(a4)
    move.b  d6,$1201(a4)

    lea.l   $A04000,a3           ; a3 - OPN2 base
    lea.l   instrument,a1
    lea.l   out_fm,a2
    moveq   #(34-1),d2
    moveq   #$ffffffb4,d4        ; we only need byte portion so we're ok
.1:
    jsr     (a2)
    subi    #4,d4
    dbf     d2,.1

    moveq   #$28,d4          ; key trigger (is this enough for the retrig?)
    jsr     (a2)
    jsr     (a2)

    moveq   #3,d7
frameloop:
    ; wait for vblank
    btst    d7,1(a6)
    bne     frameloop
;.1:
;    btst    d7,1(a6)
;    beq     .1

    ; increment frame counter
    addi     #1,d4
    move.w   d4,d0

    ; try to display something :meatjob:
    ; write crap to the tilemap
    move.l  #$60000000,0(a6)
    moveq   #(32-1),d2
    move.w  d4,d6
    lsr     #3,d6
.yloop:
    moveq   #(64-1),d1
    asr.w   #2,d0
.xloop:
    add.w   d1,d0
    sub.w   d6,d0
    sub.w   d2,d0
    move    d0,d5
    and.w   d4,d5
    move.w  d5,(a5)
    dbf     d1,.xloop
    dbf     d2,.yloop

    bra     frameloop

    ; d4: index, a1: data ptr, a3: OPN2 base+1 d7: #7   (bit test position)
out_fm:
.1:
    btst        d7,(a3)
    bne         .1
    move.b      d4,0(a3)
.2:
    btst        d7,(a3)
    bne         .2
    move.b      (a1)+,1(a3)
    rts

instrument:
    ; $B4 descending to $30 (due to the way frequency is updated...)
    dc.b   $c0      ; $b4
    dc.b   $34      ; $b0

    dc.b   $00      ; $ac (dummy)
    dc.b   $00      ; $a8 (dummy)
    dc.b   $06      ; $a4
    dc.b   $57      ; $a0

    dc.b   $08
    dc.b   $0c
    dc.b   $08
    dc.b   $0e      ; $90

    dc.b   $8f
    dc.b   $ff
    dc.b   $3f
    dc.b   $4f      ; $80

    dc.b   $16
    dc.b   $1f
    dc.b   $0f
    dc.b   $05      ; $70

    dc.b   $0a
    dc.b   $0c
    dc.b   $09
    dc.b   $05      ; $60

    dc.b   $1f
    dc.b   $1f
    dc.b   $1f
    dc.b   $1f      ; $50

    dc.b   $00
    dc.b   $00
    dc.b   $0b
    dc.b   $07      ; $40
cram_top:
    dc.b   $72
    dc.b   $41
    dc.b   $71
    dc.b   $73      ; $30

    dc.b   $00
    dc.b   $f0

    ifd PAD_TO_512B
    if * < 512
    ; fill header with junk to please shitty emulators :meatsob:
    dcb.b   512-*
    endif
    endif