cii.s 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. .define Cii
  2. .sect .text
  3. .sect .rom
  4. .sect .data
  5. .sect .bss
  6. .sect .text
  7. ! This subroutine converts integers to integers.
  8. ! Convertions of integers with the same source size as destination
  9. ! size aren't done, there just return the source.
  10. ! A convertion from 4 bytes to 2 bytes just strips the two
  11. ! most significant bytes.
  12. ! A convertion from 2 bytes to 4 bytes tests the sign of the
  13. ! source so that sign extentension takes place if neccesairy.
  14. Cii:
  15. cpx #2
  16. beq Cii_2 ! a conversion from ? to 2
  17. jsr Pop ! a conversion from 4 to ?
  18. cpx #4
  19. beq 8f ! a conversion 4 to 4 (skip)
  20. jsr Pop
  21. tay ! save A for sign test
  22. pha ! save A
  23. txa
  24. pha ! save X
  25. tya ! test on negative
  26. bmi 1f ! negative means sign extension
  27. lda #0 ! no sign extension here
  28. tax
  29. beq 2f
  30. 1: lda #0x0FF ! sign extension here
  31. tax
  32. 2: jsr Push ! push twobyte integer
  33. pla
  34. tax ! get X
  35. pla ! get A
  36. jmp Push
  37. Cii_2: ! a conversion from 2 to ?
  38. jsr Pop
  39. cpx #2
  40. beq 8f ! a conversion from 2 to 2 (skip)
  41. jsr Pop ! a conversion from 4 to 2
  42. pha ! save A
  43. txa
  44. pha ! save X
  45. jsr Pop ! strip most significant bytes
  46. pla ! get X
  47. tax
  48. pla ! get A
  49. jmp Push ! push result
  50. 8: rts