error.xyw

error.xyw
calendarsave
; .include "lib/macros.xyw"
; .include "lib/table.xyw"

; Prints the message corresponding to error b
; defined in string table st
.label print_error
  POPx  ; x = b
  POPxw ; xy = st
  PSHxw PSHx table_find JSRw               
  POPyw ; yw = s or $0000
  $0000 EQUyw print_error.unknown JCNw
  PSHyw puts JSRw
  RTS
  .label print_error.unknown
    errors.unknown puts JSRw


.label errors.table

  ; System
  .byte $00
  .string "No error"
  .byte $01
  .string "Division by zero"
  .byte $02
  .string "User stack overflow"
  .byte $03
  .string "User stack underflow"
  .byte $04
  .string "System stack overflow"
  .byte $05
  .string "System stack underflow"
  .byte $06
  .string "Execution depth exceeded"
  .byte $07
  .string "Image not found"
  .byte $08
  .string "Image read error"
  .byte $09
  .string "Image too large"
  .byte $0A
  .string "Invalid opcode"

  ; Terminal
  .byte $11
  .string "Terminal not a TTY"

  ; File
  .byte $31
  .string "File not found"
  .byte $32
  .string "Access denied"
  .byte $33
  .string "Invalid operation"
  .byte $34
  .string "Input/output error"
  .byte $35
  .string "Path too long"
  .byte $36
  .string "Buffer out of range"
  .byte $37
  .string "Symlink creation failed"
  .byte $38
  .string "Program execution failed"
  .byte $39
  .string "Splice/seek offset out of range"
  .byte $3A
  .string "File is too large"

  ; Beeper
  .byte $41
  .string "Beeper device failure"
  .byte $42
  .string "Beeper memory allocation error"
  .byte $43
  .string "Beeper playback failure"

  ; end of table 
  .byte $FF
  .label errors.unknown
  .string "Unknown error"