Skip to content

Instantly share code, notes, and snippets.

@dansalvato
Forked from 1wErt3r/SMBDIS.ASM
Last active June 26, 2023 14:55
Show Gist options
  • Save dansalvato/ef1e3d34f6af710e57a876005d8b29a7 to your computer and use it in GitHub Desktop.
Save dansalvato/ef1e3d34f6af710e57a876005d8b29a7 to your computer and use it in GitHub Desktop.

Revisions

  1. dansalvato revised this gist Oct 22, 2021. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions SMBDIS.ASM
    Original file line number Diff line number Diff line change
    @@ -12039,14 +12039,14 @@ DoPlayerSideCheck:
    sta $00

    SideCheckLoop:
    iny ;move onto the next one
    sty $eb ;store it
    iny ;increment to offset for side (left on first loop iteration,
    sty $eb ;right on second loop iteration), and store it
    lda Player_Y_Position
    cmp #$20 ;check player's vertical position
    bcc BHalf ;if player is in status bar area, branch ahead to skip this part
    cmp #$e4
    bcs ExSCH ;branch to leave if player is too far down
    jsr BlockBufferColli_Side ;do player-to-bg collision detection on one half of player
    jsr BlockBufferColli_Side ;do player-to-bg collision detection on top of player's side
    beq BHalf ;branch ahead if nothing found
    cmp #$1c ;otherwise check for pipe metatiles
    beq BHalf ;if collided with sideways pipe (top), branch ahead
    @@ -12061,7 +12061,7 @@ BHalf: ldy $eb ;load block adder offset
    bcc ExSCH ;if too high, branch to leave
    cmp #$d0
    bcs ExSCH ;if too low, branch to leave
    jsr BlockBufferColli_Side ;do player-to-bg collision detection on other half of player
    jsr BlockBufferColli_Side ;do player-to-bg collision detection on bottom of player's side
    bne CheckSideMTiles ;if something found, branch
    dec $00 ;otherwise decrement counter
    bne SideCheckLoop ;run code until both sides of player are checked
  2. dansalvato revised this gist Oct 22, 2021. 1 changed file with 50 additions and 48 deletions.
    98 changes: 50 additions & 48 deletions SMBDIS.ASM
    Original file line number Diff line number Diff line change
    @@ -314,22 +314,22 @@ Block_X_Position = $8f
    Misc_X_Position = $93
    Bubble_X_Position = $9c

    SprObject_Y_Speed = $9f
    SprObject_Y_Spd_Hi = $9f
    Player_Y_Speed = $9f
    Enemy_Y_Speed = $a0
    Fireball_Y_Speed = $a6
    Block_Y_Speed = $a8
    Misc_Y_Speed = $ac

    SprObject_Y_HighPos = $b5
    SprObject_Y_Pos_Pg = $b5
    Player_Y_HighPos = $b5
    Enemy_Y_HighPos = $b6
    Fireball_Y_HighPos = $bc
    Block_Y_HighPos = $be
    Misc_Y_HighPos = $c2
    Bubble_Y_HighPos = $cb

    SprObject_Y_Position = $ce
    SprObject_Y_Pos_Hi = $ce
    Player_Y_Position = $ce
    Enemy_Y_Position = $cf
    Fireball_Y_Position = $d5
    @@ -360,12 +360,12 @@ Enemy_SprAttrib = $03c5
    SprObject_X_MoveForce = $0400
    Enemy_X_MoveForce = $0401

    SprObject_YMF_Dummy = $0416
    SprObject_Y_Pos_Lo = $0416
    Player_YMF_Dummy = $0416
    Enemy_YMF_Dummy = $0417
    Bubble_YMF_Dummy = $042c

    SprObject_Y_MoveForce = $0433
    SprObject_Y_Spd_Lo = $0433
    Player_Y_MoveForce = $0433
    Enemy_Y_MoveForce = $0434
    Block_Y_MoveForce = $043c
    @@ -7704,63 +7704,65 @@ RedPTroopaGrav:
    ;-------------------------------------------------------------------------------------
    ;$00 - used for downward force
    ;$01 - used for upward force
    ;$07 - used as adder for vertical position
    ;$02 - used for maximum speed
    ;$07 - used to help set Y page number, and as the negative of max speed (for ChkUpM)
    ;A - used to skip ChkUpM

    ImposeGravity:
    pha ;push value to stack
    lda SprObject_YMF_Dummy,x
    clc ;add value in movement force to contents of dummy variable
    adc SprObject_Y_MoveForce,x
    sta SprObject_YMF_Dummy,x
    pha ;push value to stack (for skipping ChkUpM)
    lda SprObject_Y_Pos_Lo,x
    clc
    adc SprObject_Y_Spd_Lo,x ;add speed low byte to position low byte
    sta SprObject_Y_Pos_Lo,x ;and store it
    ldy #$00 ;set Y to zero by default
    lda SprObject_Y_Speed,x ;get current vertical speed
    lda SprObject_Y_Spd_Hi,x ;get current vertical speed
    bpl AlterYP ;if currently moving downwards, do not decrement Y
    dey ;otherwise decrement Y
    AlterYP: sty $07 ;store Y here
    adc SprObject_Y_Position,x ;add vertical position to vertical speed plus carry
    sta SprObject_Y_Position,x ;store as new vertical position
    lda SprObject_Y_HighPos,x
    adc $07 ;add carry plus contents of $07 to vertical high byte
    sta SprObject_Y_HighPos,x ;store as new vertical high byte
    lda SprObject_Y_MoveForce,x
    adc SprObject_Y_Pos_Hi,x ;add speed and position, plus carry from low byte position
    sta SprObject_Y_Pos_Hi,x ;store as new vertical position
    lda SprObject_Y_Pos_Pg,x
    adc $07 ;add carry plus contents of $07 to Y page number
    sta SprObject_Y_Pos_Pg,x ;store as new Y page number
    lda SprObject_Y_Spd_Lo,x
    clc
    adc $00 ;add downward movement amount to contents of $0433
    sta SprObject_Y_MoveForce,x
    lda SprObject_Y_Speed,x ;add carry to vertical speed and store
    adc $00 ;add downward movement amount to Y speed low byte
    sta SprObject_Y_Spd_Lo,x
    lda SprObject_Y_Spd_Hi,x ;add carry to Y speed high byte and store
    adc #$00
    sta SprObject_Y_Speed,x
    cmp $02 ;compare to maximum speed
    bmi ChkUpM ;if less than preset value, skip this part
    lda SprObject_Y_MoveForce,x
    cmp #$80 ;if less positively than preset maximum, skip this part
    sta SprObject_Y_Spd_Hi,x
    cmp $02 ;compare Y speed to maximum speed
    bmi ChkUpM ;if less than max speed, skip this part
    lda SprObject_Y_Spd_Lo,x
    cmp #$80 ;if Y speed low byte < 0x80, skip this part
    bcc ChkUpM
    lda $02
    sta SprObject_Y_Speed,x ;keep vertical speed within maximum value
    sta SprObject_Y_Spd_Hi,x ;keep Y speed within maximum value
    lda #$00
    sta SprObject_Y_MoveForce,x ;clear fractional
    sta SprObject_Y_Spd_Lo,x ;clear Y speed low byte
    ChkUpM: pla ;get value from stack
    beq ExVMove ;if set to zero, branch to leave
    lda $02
    eor #%11111111 ;otherwise get two's compliment of maximum speed
    eor #%11111111 ;otherwise invert sign of max speed
    tay
    iny
    sty $07 ;store two's compliment here
    lda SprObject_Y_MoveForce,x
    sty $07 ;store max speed here
    lda SprObject_Y_Spd_Lo,x
    sec ;subtract upward movement amount from contents
    sbc $01 ;of movement force, note that $01 is twice as large as $00,
    sta SprObject_Y_MoveForce,x ;thus it effectively undoes add we did earlier
    lda SprObject_Y_Speed,x
    sbc #$00 ;subtract borrow from vertical speed and store
    sta SprObject_Y_Speed,x
    cmp $07 ;compare vertical speed to two's compliment
    bpl ExVMove ;if less negatively than preset maximum, skip this part
    lda SprObject_Y_MoveForce,x
    cmp #$80 ;check if fractional part is above certain amount,
    sbc $01 ;of Y speed low; note that $01 is twice as large as $00,
    sta SprObject_Y_Spd_Lo,x ;thus it effectively undoes add we did earlier
    lda SprObject_Y_Spd_Hi,x
    sbc #$00 ;subtract carry from Y speed high byte and store
    sta SprObject_Y_Spd_Hi,x
    cmp $07 ;compare Y speed to max upward speed
    bpl ExVMove ;if less negative than max speed, skip this part
    lda SprObject_Y_Spd_Lo,x
    cmp #$80 ;check if Y speed low byte is above certain amount,
    bcs ExVMove ;and if so, branch to leave
    lda $07
    sta SprObject_Y_Speed,x ;keep vertical speed within maximum value
    lda #$ff
    sta SprObject_Y_MoveForce,x ;clear fractional
    sta SprObject_Y_Spd_Hi,x ;keep Y speed within maximum value
    lda #$ff ;set Y speed low byte to $ff, which reduces max upward
    sta SprObject_Y_Spd_Lo,x ;speed by nearly 1 full unit (possibly an error?)
    ExVMove: rts ;leave!

    ;-------------------------------------------------------------------------------------
    @@ -13075,7 +13077,7 @@ BlockBufferCollision:
    lsr ;d4 at this point
    jsr GetBlockBufferAddr ;get address of block buffer into $06, $07
    ldy $04 ;get old contents of Y
    lda SprObject_Y_Position,x ;get vertical coordinate of object
    lda SprObject_Y_Pos_Hi,x ;get vertical coordinate of object
    clc
    adc BlockBuffer_Y_Adder,y ;add it to value obtained using Y as offset
    and #%11110000 ;mask out low nybble
    @@ -13088,7 +13090,7 @@ BlockBufferCollision:
    ldy $04 ;get old contents of Y again
    pla ;pull A from stack
    bne RetXC ;if A = 1, branch
    lda SprObject_Y_Position,x ;if A = 0, load vertical coordinate
    lda SprObject_Y_Pos_Hi,x ;if A = 0, load vertical coordinate
    jmp RetYC ;and jump
    RetXC: lda SprObject_X_Position,x ;otherwise load horizontal coordinate
    RetYC: and #%00001111 ;and mask out high nybble
    @@ -14814,7 +14816,7 @@ VariableObjOfsRelPos:
    rts

    GetObjRelativePosition:
    lda SprObject_Y_Position,x ;load vertical coordinate low
    lda SprObject_Y_Pos_Hi,x ;load vertical coordinate low
    sta SprObject_Rel_YPos,y ;store here
    lda SprObject_X_Position,x ;load horizontal coordinate
    sec ;subtract left edge coordinate
    @@ -14958,10 +14960,10 @@ GetYOffscreenBits:
    ldy #$01 ;start with top of screen
    YOfsLoop: lda HighPosUnitData,y ;load coordinate for edge of vertical unit
    sec
    sbc SprObject_Y_Position,x ;subtract from vertical coordinate of object
    sbc SprObject_Y_Pos_Hi,x ;subtract from vertical coordinate of object
    sta $07 ;store here
    lda #$01 ;subtract one from vertical high byte of object
    sbc SprObject_Y_HighPos,x
    sbc SprObject_Y_Pos_Pg,x
    ldx DefaultYOnscreenOfs,y ;load offset value here
    cmp #$00
    bmi YLdBData ;if under top of the screen or beyond bottom, branch
  3. dansalvato revised this gist Oct 22, 2021. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions SMBDIS.ASM
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,14 @@

    ;Assembles with x816.

    ;-------------------------------------------------------------------------------------

    ;This version of SMBDIS.ASM aims to add new comments, correct/clarify existing comments,
    ;and rename some defines and labels to better describe their purpose.

    ;Contributor: Dan Salvato
    ;Last edited: 2021-10-22

    ;-------------------------------------------------------------------------------------
    ;DEFINES

  4. dansalvato revised this gist Oct 22, 2021. 1 changed file with 11 additions and 11 deletions.
    22 changes: 11 additions & 11 deletions SMBDIS.ASM
    Original file line number Diff line number Diff line change
    @@ -936,7 +936,7 @@ OperModeExecutionTree:

    MoveAllSpritesOffscreen:
    ldy #$00 ;this routine moves all sprites off the screen
    .db $2c ;BIT instruction opcode
    .db $2c ;BIT opcode - skip over the next instruction

    MoveSpritesOffscreen:
    ldy #$04 ;this routine moves all but sprite 0
    @@ -3915,7 +3915,7 @@ Hole_Water:

    QuestionBlockRow_High:
    lda #$03 ;start on the fourth row
    .db $2c ;BIT instruction opcode
    .db $2c ;BIT opcode - skip over the next instruction

    QuestionBlockRow_Low:
    lda #$07 ;start on the eighth row
    @@ -3931,11 +3931,11 @@ QuestionBlockRow_Low:

    Bridge_High:
    lda #$06 ;start on the seventh row from top of screen
    .db $2c ;BIT instruction opcode
    .db $2c ;BIT opcode - skip over the next instruction

    Bridge_Middle:
    lda #$07 ;start on the eighth row
    .db $2c ;BIT instruction opcode
    .db $2c ;BIT opcode - skip over the next instruction

    Bridge_Low:
    lda #$09 ;start on the tenth row
    @@ -7334,11 +7334,11 @@ BlockCode: jsr JumpEngine ;run appropriate subroutine depending on bloc

    MushFlowerBlock:
    lda #$00 ;load mushroom/fire flower into power-up type
    .db $2c ;BIT instruction opcode
    .db $2c ;BIT opcode - skip over the next instruction

    StarBlock:
    lda #$02 ;load star into power-up type
    .db $2c ;BIT instruction opcode
    .db $2c ;BIT opcode - skip over the next instruction

    ExtraLifeMushBlock:
    lda #$03 ;load 1-up mushroom into power-up type
    @@ -7668,11 +7668,11 @@ ImposeGravitySprObj:
    ;--------------------------------

    MovePlatformDown:
    lda #$00 ;save value to stack (if branching here, execute next
    .db $2c ;part as BIT instruction)
    lda #$00 ;save value to stack (skip ChkUpM during ImposeGravity)
    .db $2c ;BIT opcode - skip over the next instruction

    MovePlatformUp:
    lda #$01 ;save value to stack
    lda #$01 ;save value to stack (don't skip ChkUpM during ImposeGravity)
    pha
    ldy Enemy_ID,x ;get enemy object identifier
    inx ;increment offset for enemy object
    @@ -11838,7 +11838,7 @@ PositionPlayerOnS_Plat:
    lda Enemy_Y_Position,x ;for offset
    clc ;add positioning data using offset to the vertical
    adc PlayerPosSPlatData-1,y ;coordinate
    .db $2c ;BIT instruction opcode
    .db $2c ;BIT opcode - skip over the next instruction

    PositionPlayerOnVPlat:
    lda Enemy_Y_Position,x ;get vertical coordinate
    @@ -13043,7 +13043,7 @@ BlockBufferColli_Feet:

    BlockBufferColli_Head:
    lda #$00 ;set flag to return vertical coordinate
    .db $2c ;BIT instruction opcode
    .db $2c ;BIT opcode - skip over the next instruction

    BlockBufferColli_Side:
    lda #$01 ;set flag to return horizontal coordinate
  5. dansalvato revised this gist Oct 22, 2021. 1 changed file with 11 additions and 12 deletions.
    23 changes: 11 additions & 12 deletions SMBDIS.ASM
    Original file line number Diff line number Diff line change
    @@ -664,10 +664,7 @@ GameOverModeValue = 3
    ;-------------------------------------------------------------------------------------
    ;DIRECTIVES

    .index 8
    .mem 8

    .org $8000
    * = $8000

    ;-------------------------------------------------------------------------------------

    @@ -13027,17 +13024,19 @@ BBChk_E: jsr BlockBufferCollision ;do collision detection subroutine for sprite
    BlockBufferAdderData:
    .db $00, $07, $0e

    ;offsets from the left or top of player/enemy to test for block collision
    ;in order: Head, left foot, right foot, (sides) left top, left bottom, right top, right bottom
    BlockBuffer_X_Adder:
    .db $08, $03, $0c, $02, $02, $0d, $0d, $08
    .db $03, $0c, $02, $02, $0d, $0d, $08, $03
    .db $0c, $02, $02, $0d, $0d, $08, $00, $10
    .db $04, $14, $04, $04
    .db $08, $03, $0c, $02, $02, $0d, $0d ;big
    .db $08, $03, $0c, $02, $02, $0d, $0d ;big in water
    .db $08, $03, $0c, $02, $02, $0d, $0d ;small
    .db $08, $00, $10, $04, $14, $04, $04 ;enemy block collision tests

    BlockBuffer_Y_Adder:
    .db $04, $20, $20, $08, $18, $08, $18, $02
    .db $20, $20, $08, $18, $08, $18, $12, $20
    .db $20, $18, $18, $18, $18, $18, $14, $14
    .db $06, $06, $08, $10
    .db $04, $20, $20, $08, $18, $08, $18 ;big
    .db $02, $20, $20, $08, $18, $08, $18 ;big in water
    .db $12, $20, $20, $18, $18, $18, $18 ;small
    .db $18, $14, $14, $06, $06, $08, $10 ;enemy block collision tests

    BlockBufferColli_Feet:
    iny ;if branched here, increment to next set of adders
  6. @1wErt3r 1wErt3r created this gist Nov 9, 2012.
    16,352 changes: 16,352 additions & 0 deletions SMBDIS.ASM
    16,352 additions, 0 deletions not shown because the diff is too large. Please use a local Git client to view these changes.