Guest User

Untitled

a guest
Jan 23rd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. ###
  2. APPLE I 8k memory map
  3. -----------------------------------------------------------------
  4. $0FFF : End of 1st 4k memory
  5. $D010 KBD : b7 is always 1. Read KBD will clear KBDCR's b7
  6. $D011 KBDCR : When a key is pressed, b7 is set.
  7. $D012 DSP : b6...b0 is output character.
  8. Writing to DSP will set b7 by hardware
  9. After displaying the character, b7 will be cleared.
  10. $E000 : Start of 2nd 4k memory.
  11. $EFFF : End of 2nd 4k memory.
  12. $FF00 : Start of 256B ROM.
  13. $FFFF : End of 256B ROM and the memory limit
  14. -----------------------------------------------------------------
  15. ###
  16. exports.memory =
  17. rom : [
  18. 0xd8, 0x58, 0xa0, 0x7f, 0x8c, 0x12, 0xd0, 0xa9
  19. 0xa7, 0x8d, 0x11, 0xd0, 0x8d, 0x13, 0xd0, 0xc9
  20. 0xdf, 0xf0, 0x13, 0xc9, 0x9b, 0xf0, 0x03, 0xc8
  21. 0x10, 0x0f, 0xa9, 0xdc, 0x20, 0xef, 0xff, 0xa9
  22. 0x8d, 0x20, 0xef, 0xff, 0xa0, 0x01, 0x88, 0x30
  23. 0xf6, 0xad, 0x11, 0xd0, 0x10, 0xfb, 0xad, 0x10
  24. 0xd0, 0x99, 0x00, 0x02, 0x20, 0xef, 0xff, 0xc9
  25. 0x8d, 0xd0, 0xd4, 0xa0, 0xff, 0xa9, 0x00, 0xaa
  26. 0x0a, 0x85, 0x2b, 0xc8, 0xb9, 0x00, 0x02, 0xc9
  27. 0x8d, 0xf0, 0xd4, 0xc9, 0xae, 0x90, 0xf4, 0xf0
  28. 0xf0, 0xc9, 0xba, 0xf0, 0xeb, 0xc9, 0xd2, 0xf0
  29. 0x3b, 0x86, 0x28, 0x86, 0x29, 0x84, 0x2a, 0xb9
  30. 0x00, 0x02, 0x49, 0xb0, 0xc9, 0x0a, 0x90, 0x06
  31. 0x69, 0x88, 0xc9, 0xfa, 0x90, 0x11, 0x0a, 0x0a
  32. 0x0a, 0x0a, 0xa2, 0x04, 0x0a, 0x26, 0x28, 0x26
  33. 0x29, 0xca, 0xd0, 0xf8, 0xc8, 0xd0, 0xe0, 0xc4
  34. 0x2a, 0xf0, 0x97, 0x24, 0x2b, 0x50, 0x10, 0xa5
  35. 0x28, 0x81, 0x26, 0xe6, 0x26, 0xd0, 0xb5, 0xe6
  36. 0x27, 0x4c, 0x44, 0xff, 0x6c, 0x24, 0x00, 0x30
  37. 0x2b, 0xa2, 0x02, 0xb5, 0x27, 0x95, 0x25, 0x95
  38. 0x23, 0xca, 0xd0, 0xf7, 0xd0, 0x14, 0xa9, 0x8d
  39. 0x20, 0xef, 0xff, 0xa5, 0x25, 0x20, 0xdc, 0xff
  40. 0xa5, 0x24, 0x20, 0xdc, 0xff, 0xa9, 0xba, 0x20
  41. 0xef, 0xff, 0xa9, 0xa0, 0x20, 0xef, 0xff, 0xa1
  42. 0x24, 0x20, 0xdc, 0xff, 0x86, 0x2b, 0xa5, 0x24
  43. 0xc5, 0x28, 0xa5, 0x25, 0xe5, 0x29, 0xb0, 0xc1
  44. 0xe6, 0x24, 0xd0, 0x02, 0xe6, 0x25, 0xa5, 0x24
  45. 0x29, 0x07, 0x10, 0xc8, 0x48, 0x4a, 0x4a, 0x4a
  46. 0x4a, 0x20, 0xe5, 0xff, 0x68, 0x29, 0x0f, 0x09
  47. 0xb0, 0xc9, 0xba, 0x90, 0x02, 0x69, 0x06, 0x2c
  48. 0x12, 0xd0, 0x30, 0xfb, 0x8d, 0x12, 0xd0, 0x60
  49. 0x00, 0x00, 0x00, 0x0f, 0x00, 0xff, 0x00, 0x00
  50. ]
  51. cells : []
  52. read : (adr) ->
  53. @cells[adr]
  54. write : (adr, val) ->
  55. @cells[adr] = val if (0 <= adr < 0x1000 or 0xE000 <= adr < 0xF000)
  56. @cells[adr] = (val % 128) + 128 if (adr is 0xD012)
  57. return
  58. init : () ->
  59. @cells[adr] = 0 for adr in [0..0xFFFF]
  60. @cells[0xFF00..0xFFFF] = @rom
  61. return
  62.  
  63. exports.pia6820 =
  64. KBD : 0xD010
  65. KBDCR : 0xD011
  66. DSP : 0xD012
  67. run : () ->
  68. c = exports.memory.read(@DSP)
  69. if c >= 128
  70. c = c % 128 # clear bit 7
  71. console.log(String.fromCharCode(c))
  72. exports.memory.cells[@DSP] = c #clear bit 7 by hardware on DSP
  73. return
  74. else
  75. return
  76.  
  77. exports.m6502 =
  78. # registeres
  79. A : 0
  80. X : 0
  81. Y : 0
  82. S : 0 # stack pointer
  83. P : 0 # processor status
  84. PC : 0 # 16 bit little endian
  85. # status flag
  86. N : 0x80
  87. V : 0x40
  88. M : 0x20
  89. B : 0x10
  90. D : 0x08
  91. I : 0x04
  92. Z : 0x02
  93. C : 0x01
  94. # signal & synchronization
  95. cyc : 0
  96.  
  97. fetch : () ->
  98. console.log "#{@PC}:#{exports.memory.read(@PC)}"
  99. return exports.memory.read(@PC++)
  100.  
  101. trace : () ->
  102. console.log "A #{@A} X #{@X} Y #{@Y} S #{@S} P #{@P} PC #{@PC}"
  103. return
  104.  
  105. run : () ->
  106. switch @fetch()
  107. when 0x2C # BIT ABS
  108. @P = @P & (~ @Z)
  109. @P = @P & (~ @N)
  110. @P = @P & (~ @V)
  111. l = @fetch()
  112. h = @fetch()
  113. x = exports.memory.read((h << 8) + l)
  114. if (@A & x) is 0
  115. @P = @P | @Z
  116. @P = @P | (x & @N)
  117. @P = @P | (x & @V)
  118. when 0x30 # BMI REL
  119. rel = @fetch()
  120. if (rel > 0x7F)
  121. rel = -( (~rel & 0xFF) + 1)
  122. if (@P & @N)
  123. @PC = @PC + rel
  124. when 0x60 # RTS
  125. if @S < 1 then @S = 0xFF else @S--
  126. @PC = exports.memory.read(0x100 + @S)
  127. when 0x8D # STA ABS
  128. l = @fetch()
  129. h = @fetch()
  130. exports.memory.write((h << 8) + l, @A)
  131. @trace()
Add Comment
Please, Sign In to add comment