SHARE
TWEET

GS VC ACE Bootstrap source.

luckytyphlosion Jan 2nd, 2018 (edited) 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; 1 char: flags 1
  2. ; bit 0-1: sram bank
  3. ; bit 2: bootstrap or execute
  4. ; bit 3: specify bootstrap mail buffer scratch dest
  5. ; bit 4: base16 or hex encoding. base16 assumes little endian, hex encoding assumes big endian
  6. ; if upper 7 bits are %1110001 (- or /), execute directly. bit 4 corresponds to jump encoding
  7. ; 4 chars: bootstrap dest or execute src
  8. ; 1 char: flags 2
  9. ; bit 0: don't include header
  10.  
  11. hChecksumPrint EQU $ffe9
  12.  
  13. callw2: MACRO
  14.     IF _NARG == 1
  15.         call (\1 - CharPairPointerDecode) + wCmdQueue + 6 * 4
  16.     ELSE
  17.         call \1, (\2 - CharPairPointerDecode) + wCmdQueue + 6 * 4
  18.     ENDC
  19. ENDM
  20.  
  21.     callw _Bootstrap
  22.     jp CloseSRAM
  23.  
  24. _Bootstrap::
  25.     ld hl, wBoxNames
  26.     ld a, [hli]
  27.     ld b, a
  28.     add a
  29.     jr c, .headerNotFromMail
  30.     push hl
  31.     ld de, wc1d5
  32.     push de
  33.     callba $4, _ComposeMailMessage
  34.     pop de
  35.     ld a, [de]
  36.     res 7, a
  37.     ld [de], a
  38.     ld b, a
  39.     ld hl, wBoxNames
  40.     call CopyName2 
  41.     pop hl
  42. .headerNotFromMail
  43.     callw2 CharPairPointerDecode
  44.     ld h, d
  45.     ld l, e ; hl = bootstrap dest or execute src
  46.     ld a, b
  47.     cp "-"
  48.     jr c, .notDirectExecute
  49.     jp hl
  50. .notDirectExecute
  51.     and $3
  52.     bit 2, b
  53.     jr z, .bootstrap
  54.     call OpenSRAM
  55.     ld a, [hli]
  56.     ld b, a
  57.     ld a, [hli]
  58.     ld c, a
  59.     ld a, [hli]
  60.     ld d, a
  61.     ld a, [hli]
  62.     ld e, a
  63.     push de ; execute dest
  64.     jp CopyBytes ; returns into de, which is the destination
  65. .bootstrap
  66.     bit 3, b ; specify bootstrap buffer dest
  67.     push af
  68.     push de ; save dest for later
  69.     ld de, $c755 ; default
  70.     ld hl, wBoxNames + 9 * 2
  71.     callw2 nz, CharPairPointerDecode
  72.     push de
  73. .getBootstrapCharsLoop
  74.     push de ; push mail dest buffer
  75. .retryMail
  76.     ld de, wc1d5 ; temp buffer for mail message
  77.     callba $4, _ComposeMailMessage
  78.     pop de ; get mail dest buffer
  79.     push de ; push mail dest buffer
  80.     ld hl, wc1d5
  81.     ld bc, 0
  82.     jr .handleLoop
  83. ; hl = temp mail buffer
  84. ; de = scratch space dest
  85. .checksumMsgLoop
  86.     callw2 CharPairDecode
  87.     ld [de], a
  88.     inc de
  89.     add c
  90.     ld c, a
  91.     jr nc, .handleLoop
  92.     inc b
  93. .handleLoop
  94.     callw CheckNewlineChar
  95.     ld a, [hl]
  96.     cp "@"
  97.     jr z, .doneChecksum
  98.     cp "!"
  99.     jr nz, .checksumMsgLoop
  100. .doneChecksum
  101.     push af ; push "!" flag
  102.     push de ; push end of compiled message
  103.     ld hl, hChecksumPrint + 1
  104.     ld a, c
  105.     ld [hld], a
  106.     ld [hl], b
  107.     ld d, h
  108.     ld e, l
  109.     coord hl, 5, 0
  110.     lb bc, PRINTNUM_LEADINGZEROS | PRINTNUM_LEFTALIGN | 2, 5
  111.     call PrintNum ; leftover function in GS
  112.     call YesNoBox
  113.     pop de ; pop end of compiled message
  114.     pop bc ; pop flags
  115.  
  116.     jr c, .retryMail
  117.     pop hl ; pop start of mail message (ignored)
  118.     bit 0, b ; "@" has bit 0 set
  119.     jr z, .getBootstrapCharsLoop
  120. .bootstrapFinished
  121. ; perform de - hl
  122.     pop hl
  123.     ld a, e
  124.     sub l
  125.     ld c, a
  126.     ld a, d
  127.     sbc h
  128.     ld b, a
  129.     pop de ; sram dest
  130.     pop af ; sram bank
  131.     call OpenSRAM
  132.     ld a, [wBoxNames + 5]
  133.     rra
  134.     jr c, .noHeader
  135.     dec bc
  136.     dec bc
  137.     ld a, b
  138.     ld [de], a
  139.     inc de
  140.     ld a, c
  141.     ld [de], a
  142.     inc de
  143.     inc bc
  144.     inc bc
  145. .noHeader
  146.     jp CopyBytes
  147.  
  148. CheckNewlineChar:
  149.     ld a, [hl]
  150.     cp $4e
  151.     ret nz
  152.     inc hl
  153.     ret
  154.  
  155. ; sectioned at unused space after wCmdQueue
  156. CharPairPointerDecode:
  157.     callw2 CharPairDecode
  158.     ld d, a
  159.     callw2 CharPairDecode
  160.     ld e, a
  161.     ret
  162.  
  163. CharPairDecode:
  164.     push bc
  165.     callw2 ReadAndFilterChar
  166.     add a
  167.     add a
  168.     add a
  169.     add a
  170.     ld b, a
  171.     callw2 ReadAndFilterChar
  172.     and $f
  173.     or b
  174.     pop bc
  175.     ret
  176.  
  177. ReadAndFilterChar:
  178.     callw CheckNewlineChar
  179.     ld a, [wBoxNames]
  180.     bit 4, a
  181.     ld a, [hli]
  182.     ret z
  183.     add a, 10
  184.     ret
  185.  
  186. ; event flags
  187. ; unused: d7d7 to d7ff
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top