Settings

Theme

Show HN: I wrote a website in 6502 assembly

mdw.la

20 points by mdwelsh 5 years ago · 2 comments

Reader

Tepix 5 years ago

Neat. The main source code file appears to be https://github.com/mdwelsh/mdwos/blob/main/mdwos/mdwos.s

in particular i was curious to see how the emulated Apple II managed to open links:

    OPENLINK = $C06C      ; MDWOS special
    ;; doopenlink
    ;;
    ;; Open a web page link. This is done by triggering a hack in the appleiijs 
    ;; emulator that I added, which pulls the URL out of the memory address pointed
    ;; to by OPENLINKURL,OPENLINKURL2.
    doopenlink:
      ; On entry, the return address-1 is on the stack.
      ; This will be the first byte of the URL we want to open.
      ; So, we read that 16-bit address off the stack and store
      ; it in OPENLINKURL / OPENLINKURL+1.
      PLA
      STA OPENLINKURL
      STA PRINTPTR
      PLA
      STA OPENLINKURL2
      STA PRINTPTR+1
    
      ; Before we open the link, we need to advance the return address
      ; to the end of the URL string.
      LDY #0
    @skipurlloop:
      ; We inc here because the address we pulled off the stack was
      ; the return address-1.
      INC PRINTPTR
      BNE @noc3  ; If no carry
      INC PRINTPTR+1
    @noc3:
      ; Load the next character
      LDA (PRINTPTR),Y
      ; If null, stop skipping.
      BEQ @skipurlend
      JMP @skipurlloop
    @skipurlend:
      ; Now, we take the current pointer into the string we were skipping
      ; and push it back on the stack as the return address.
      ; This will resume execution after the string.
      LDA PRINTPTR+1
      PHA
      LDA PRINTPTR
      PHA
    
      ; Finally, jump to the link.
      ; Obviously this won't work on a non-MDWOS enabled machine.
      LDA OPENLINK
      RTS

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection