home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / misc / apple.asm < prev    next >
Assembly Source File  |  1990-05-30  |  21KB  |  571 lines

  1.     Page    58,132
  2.     Title    APPLE.ASM    Apple Emulator (65C02 Processor)
  3. ;******************************************************************************
  4. ;
  5. ;   Name:    APPLE.ASM    Apple Emulator (65C02 Processor)
  6. ;
  7. ;   Group:    Emulator
  8. ;
  9. ;   Revision:    1.00
  10. ;
  11. ;   Date:    January 30, 1988
  12. ;
  13. ;   Author:    Randy W. Spurlock
  14. ;
  15. ;******************************************************************************
  16. ;
  17. ;  Module Functional Description:
  18. ;
  19. ;        This module contains all the code for the Apple
  20. ;    specific part of the Apple emulator.
  21. ;
  22. ;******************************************************************************
  23. ;
  24. ;  Changes:
  25. ;
  26. ;    DATE     REVISION                DESCRIPTION
  27. ;  --------   --------    -------------------------------------------------------
  28. ;   1/30/88    1.00    Original
  29. ;
  30. ;******************************************************************************
  31.     Page
  32. ;
  33. ;  Public Declarations
  34. ;
  35.     Public    Initialize        ; Apple emulator initialization routine
  36.     Public    Read_Memory        ; Read 65C02 Apple memory routine
  37.     Public    Write_Memory        ; Write 65C02 Apple memory routine
  38.     Public    System_Reset        ; Apple system reset routine (Interrupt)
  39.     Public    System_Request        ; System request routine (Interrupt)
  40.     Public    Reset_System        ; Apple reset system routine
  41.     Public    Request_System        ; Apple request system routine
  42.     Public    Error            ; Apple emulator error routine
  43.     Public    Exit            ; Apple emulator exit routine
  44. ;
  45. ;  External Declarations
  46. ;
  47.     Extrn    Memory_Init:Near    ; Memory initialization routine(MEMORY)
  48.     Extrn    Device_Init:Near    ; Device initialization routine(DEVICE)
  49.     Extrn    Video_Init:Near     ; Video initialization routine    (VIDEO)
  50.     Extrn    Video_Reset:Near    ; Video reset routine        (VIDEO)
  51.     Extrn    Int_Init:Near        ; Interrupt initialization      (INT)
  52.     Extrn    Int_Reset:Near        ; Interrupt reset routine      (INT)
  53.     Extrn    TTY_Init:Near        ; Initialize TTY mode routine      (TTY)
  54.     Extrn    TTY_Reset:Near        ; Reset TTY mode routine      (TTY)
  55.     Extrn    Write_TTY:Near        ; Write TTY routine          (TTY)
  56.     Extrn    Set_Position:Near    ; Set current position routine      (TTY)
  57.     Extrn    Set_Row:Near        ; Set current row routine      (TTY)
  58.     Extrn    Set_Column:Near     ; Set current column routine      (TTY)
  59.     Extrn    Set_Attribute:Near    ; Set current attribute routine   (TTY)
  60.     Extrn    Set_Foreground:Near    ; Set current foreground routine  (TTY)
  61.     Extrn    Set_Background:Near    ; Set current background routine  (TTY)
  62.     Extrn    Set_Cursor:Near     ; Set cursor position routine      (TTY)
  63.     Extrn    Set_Type:Near        ; Set cursor type routine      (TTY)
  64.     Extrn    Get_Position:Near    ; Get current position routine      (TTY)
  65.     Extrn    Get_Row:Near        ; Get current row routine      (TTY)
  66.     Extrn    Get_Column:Near     ; Get current column routine      (TTY)
  67.     Extrn    Get_Attribute:Near    ; Get current attribute routine   (TTY)
  68.     Extrn    Get_Foreground:Near    ; Get current foreground routine  (TTY)
  69.     Extrn    Get_Background:Near    ; Get current background routine  (TTY)
  70.     Extrn    Get_Cursor:Near     ; Get cursor position routine      (TTY)
  71.     Extrn    Get_Type:Near        ; Get cursor type routine      (TTY)
  72.     Extrn    Clear_Screen:Near    ; Clear screen routine          (TTY)
  73.     Extrn    Scroll_Up:Near        ; Scroll window up routine     (WINDOW)
  74.     Extrn    Scroll_Down:Near    ; Scroll window down routine   (WINDOW)
  75.     Extrn    Clear_Window:Near    ; Clear window routine           (WINDOW)
  76.     Extrn    Save_Window:Near    ; Save window routine           (WINDOW)
  77.     Extrn    Restore_Window:Near    ; Restore window routine       (WINDOW)
  78.     Extrn    Flush_Keyboard:Near    ; Flush keyboard routine     (KEYBOARD)
  79.     Extrn    Get_Key:Near        ; Get keyboard code routine  (KEYBOARD)
  80.     Extrn    Printf:Near        ; Generic Printf routine       (PRINTF)
  81.     Extrn    Set_LED:Near        ; Set keyboard LED routine   (KEYBOARD)
  82.     Extrn    Key_Reset:Near        ; Keyboard reset routine     (KEYBOARD)
  83.     Extrn    Key_Status:Byte     ; Keyboard status byte         (KEYBOARD)
  84.     Extrn    Last_Key:Byte        ; Last keyboard scan code    (KEYBOARD)
  85.     Extrn    Error_Table:Word    ; Error string table         (DATA)
  86.     Extrn    System_ROM:Word     ; Apple system ROM file name     (DATA)
  87.     Extrn    Read_Table:Word     ; Read memory page table     (DATA)
  88.     Extrn    Write_Table:Word    ; Write memory page table     (DATA)
  89.     Extrn    System_Flag:Byte    ; Apple emulator system flag byte(DATA)
  90.     Extrn    Emulate_Flag:Byte    ; Emulator system flag byte     (DATA)
  91.     Extrn    RAM_Space:Word        ; RAM space segment value     (DATA)
  92.     Extrn    ALT_Space:Word        ; Alternate RAM space segment     (DATA)
  93.     Extrn    ERR_NO_MEMORY:Abs    ; Not enough memory error code     (DATA)
  94.     Extrn    ERR_NO_SYSTEM_FILE:Abs    ; No system ROM file error code  (DATA)
  95.     Extrn    ERR_BAD_SYSTEM_FILE:Abs ; Bad system ROM file error code (DATA)
  96.     Extrn    ERR_BAD_SYSTEM_IMAGE:abs; Bad system ROM image error code(DATA)
  97. ;
  98. ;  LOCAL Equates
  99. ;
  100. SYSTEM_ADDRESS    Equ    0D000h        ; Apple system ROM load address
  101. SYSTEM_SIZE    Equ    3000h        ; Apple system ROM size (Bytes)
  102. OP_SIZE     Equ    80h        ; Op-code work area size (128 Bytes)
  103. OP_BASE     Equ    07h        ; Op-code work area base (Op_Size Log 2)
  104. ;
  105. ;  Define any include files needed
  106. ;
  107.     Include     Macros.inc    ; Include the macro definitions
  108.     Include     Equates.inc    ; Include the equate definitions
  109.     .286c                ; Include 80286 instructions
  110.     Page
  111. ;
  112. ;  Define the emulator code segment
  113. ;
  114. Emulate Segment Word Public 'EMULATE'   ; Emulator code segment
  115.     Assume    cs:Emulate, ds:Nothing, es:Nothing
  116.     Subttl    Initialize    Initialize the Apple Emulator
  117.     Page    +
  118. ;******************************************************************************
  119. ;
  120. ;    Initialize()
  121. ;
  122. ;        Clear direction flag (All moves are forward)
  123. ;        Try to allocate the 65C02 RAM space (64k)
  124. ;        If able to allocate the RAM space
  125. ;            Call routine to initialize memory
  126. ;            Call routine to load the Apple system ROM
  127. ;            Call routine to initialize expansion slot devices
  128. ;            Call routine to initialize interrupts
  129. ;            Call routine to initialize video system
  130. ;            Call routine to initilize keyboard LED's
  131. ;            Try to allocate the alternate 65C02 RAM space (64k)
  132. ;            If able to allocate the RAM space
  133. ;                Save the alternate RAM space segment
  134. ;                Call routine to initialize memory
  135. ;                Call routine to setup 65C02 registers (Reset)
  136. ;            Else unable to allocate the needed RAM space
  137. ;                Set error code to not enough memory
  138. ;                Call the error routine
  139. ;                Call routine to exit the emulator
  140. ;            Endif
  141. ;        Else unable to allocate the needed RAM space
  142. ;            Set error code to not enough memory
  143. ;            Call the error routine
  144. ;            Call routine to exit the emulator
  145. ;        Endif
  146. ;        Return to the caller
  147. ;
  148. ;    Registers on Entry:
  149. ;
  150. ;        None
  151. ;
  152. ;    Registers on Exit:
  153. ;
  154. ;        DL    - Accumulator initialized        (0h)
  155. ;        DH    - 65C02 flags initialized        (0h)
  156. ;        CL    - Y index register initialized   (0h)
  157. ;        CH    - X index register initialized   (0h)
  158. ;        BX    - Stack pointer initialized    (1FFh)
  159. ;        SI    - Program counter initialized (FFFCh)
  160. ;        DS    - 65C02 RAM space
  161. ;        ES    - Video RAM segment
  162. ;
  163. ;******************************************************************************
  164.         Even            ; Force procedure to even address
  165. Initialize    Proc    Near        ; Emulator initialization procedure
  166.     cld                ; Clear direction flag (All forward)
  167.     mov    ah,ALLOCATE_MEMORY    ; Get the allocate memory function code
  168.     mov    bx,RAM_SIZE        ; Get number of paragraphs to allocate
  169.     int    DOS            ; Try to allocate the 65C02 RAM space
  170.     jnc    Continue        ; Jump if no errors allocating space
  171. Memory_Error:
  172.     mov    al,ERR_NO_MEMORY    ; Get not enough memory error code
  173.     call    Error            ; Call routine to print the error
  174.     call    Exit            ; Call routine to exit the emulator
  175. Continue:
  176.     mov    ds,ax            ; Setup RAM space segment address
  177.     mov    cs:[RAM_Space],ax    ; Save the RAM space segment address
  178.     call    Memory_Init        ; Call routine to initialize memory
  179.     call    Load_System        ; Call routine to load system ROM
  180.     call    Device_Init        ; Call routine to initialize devices
  181.     call    Int_Init        ; Call routine to initialize interrupts
  182.     call    Video_Init        ; Call routine to initialize video
  183.     call    Set_LED         ; Call routine to initialize LED's
  184.     mov    ah,ALLOCATE_MEMORY    ; Get the allocate memory function code
  185.     mov    bx,RAM_SIZE        ; Get number of paragraphs to allocate
  186.     int    DOS            ; Try to allocate the 65C02 RAM space
  187.     jc    Memory_Error        ; Jump if errors allocating space
  188.     mov    cs:[ALT_Space],ax    ; Save alternate RAM space segment
  189.     mov    ds,ax            ; Setup RAM space segment address
  190.     call    Memory_Init        ; Call routine to initialize memory
  191.     mov    ds,cs:[RAM_Space]    ; Setup the 65C02 RAM space segment
  192.     call    CPU_Init        ; Call CPU initialize routine
  193.     ret                ; Return to the caller
  194. Initialize    Endp            ; End of the Initialize procedure
  195.     Subttl    Load_System    Load the Apple System ROM
  196.     Page    +
  197. ;******************************************************************************
  198. ;
  199. ;    Load_System(RAM_Space)
  200. ;
  201. ;        Try to open the Apple System ROM data file
  202. ;        If no errors opening the System ROM file
  203. ;            Try to read in the System ROM image
  204. ;            If errors reading the System ROM
  205. ;                Set error code to bad System ROM file
  206. ;                Call the error routine
  207. ;                Call routine to exit the emulator
  208. ;            Endif
  209. ;            Close the System ROM file
  210. ;        Else errors opening the System ROM file
  211. ;            Set error code to no System ROM file
  212. ;            Call the error routine
  213. ;            Call routine to exit the emulator
  214. ;        Endif
  215. ;        Return to the caller
  216. ;
  217. ;    Registers on Entry:
  218. ;
  219. ;        DS    - 65C02 RAM space
  220. ;
  221. ;    Registers on Exit:
  222. ;
  223. ;        AX-DX - Destroyed
  224. ;        SI-DI - Destroyed
  225. ;
  226. ;******************************************************************************
  227.         Even            ; Force procedure to even address
  228. Load_System    Proc    Near        ; Load System ROM procedure
  229.     mov    ax,cs            ; Get the current code segment value
  230.     mov    bx,ds            ; Save 65C02 RAM space segment value
  231.     mov    ds,ax            ; Setup to open the system ROM file
  232.     mov    ah,OPEN_FILE        ; Get the open file function code
  233.     mov    al,READ_ONLY        ; Get the read file access code
  234.     lea    dx,cs:[System_ROM]    ; Get pointer to system ROM file name
  235.     int    DOS            ; Try to open the system ROM file
  236.     jnc    Read_System_ROM     ; Jump if no errors opening file
  237.     mov    al,ERR_NO_SYSTEM_FILE    ; Get no system ROM file error code
  238. System_ROM_Error:
  239.     call    Error            ; Call routine to print the error
  240.     call    Exit            ; Call routine to exit emulator
  241. Read_System_ROM:
  242.     mov    ds,bx            ; Restore 65C02 RAM space segment value
  243.     mov    bx,ax            ; Move file handle to BX register
  244.     mov    ah,READ_FILE        ; Get read file function code
  245.     mov    dx,SYSTEM_ADDRESS    ; Setup the data buffer address
  246.     mov    cx,SYSTEM_SIZE        ; Get the system ROM image size (12k)
  247.     int    DOS            ; Try to read the system ROM image
  248.     mov    cx,ax            ; Save ROM image size in CX register
  249.     mov    al,ERR_BAD_SYSTEM_FILE    ; Get bad system ROM file error code
  250.     jc    System_ROM_Error    ; Jump if error trying to read the file
  251.     cmp    cx,SYSTEM_SIZE        ; Check for all of image read in
  252.     mov    al,ERR_BAD_SYSTEM_IMAGE ; Get bad system ROM image error code
  253.     jne    System_ROM_Error    ; Jump if part of image missing
  254.     mov    ah,CLOSE_FILE        ; Get close file function code
  255.     int    DOS            ; Close the system ROM file
  256.     ret                ; Return to the caller
  257. Load_System    Endp            ; End of the Load_System procedure
  258.     Subttl    CPU_Init    Initialize the 65C02 CPU Registers
  259.     Page    +
  260. ;******************************************************************************
  261. ;
  262. ;    CPU_Init()
  263. ;
  264. ;        Initialize the accumulator register            (0h)
  265. ;        Initialize the X index register             (0h)
  266. ;        Initialize the Y index register             (0h)
  267. ;        Initialize the stack pointer register              (1FFh)
  268. ;        Initialize the program counter register          (FFFCh)
  269. ;        Initialize the 65C02 processor status register        (0h)
  270. ;        Return to the caller
  271. ;
  272. ;    Registers on Entry:
  273. ;
  274. ;        DS    - 65C02 RAM space
  275. ;
  276. ;    Registers on Exit:
  277. ;
  278. ;        DL    - Accumulator initialized        (0h)
  279. ;        DH    - 65C02 flags initialized        (0h)
  280. ;        CL    - Y index register initialized   (0h)
  281. ;        CH    - X index register initialized   (0h)
  282. ;        BX    - Stack pointer initialized    (1FFh)
  283. ;        SI    - PC initialized         (Reset Vector)
  284. ;
  285. ;******************************************************************************
  286.         Even            ; Force procedure to even address
  287. CPU_Init    Proc    Near        ; Initialize CPU registers procedure
  288.     xor    dl,dl            ; Initialize the accumualtor register
  289.     xor    ch,ch            ; Initialize the X index register
  290.     xor    cl,cl            ; Initialize the Y index register
  291.     mov    bx,STACK_TOP        ; Initialize the stack pointer
  292.     mov    si,ds:[RST_VECTOR]    ; Initialize the program counter
  293.     xor    dh,dh            ; Initialize 65C02 processor flags
  294.     ret                ; Return to the caller
  295. CPU_Init    Endp            ; End of the CPU_Init procedure
  296.     Subttl    Error        Emulator Error Routine
  297.     Page    +
  298. ;******************************************************************************
  299. ;
  300. ;    Error(Error_Code)
  301. ;
  302. ;        Save the required registers
  303. ;        Print the correct error message
  304. ;        Restore the required registers
  305. ;        Return to the caller
  306. ;
  307. ;    Registers on Entry:
  308. ;
  309. ;        AL    - Error code
  310. ;
  311. ;    Registers on Exit:
  312. ;
  313. ;        AX-DX - Destroyed
  314. ;
  315. ;******************************************************************************
  316.         Even            ; Force procedure to even address
  317. Error        Proc    Near        ; Emulator error procedure
  318.     Save    ds            ; Save the required registers
  319.     xor    ah,ah            ; Convert error code to full word
  320.     shl    ax,1            ; Convert error code to table index
  321.     mov    bx,ax            ; Move table index into BX register
  322.     mov    si,cs:[bx+Error_Table]    ; Get the error string address
  323.     mov    ax,cs            ; Get current CS register value
  324.     mov    ds,ax            ; Setup to access the error string
  325.     mov    ah,WRITE_FILE        ; Get write file function code
  326.     mov    bx,STD_ERROR        ; Get the standard error handle
  327.     lodsb                ; Get the length of the error string
  328.     mov    cl,al            ; Move string length into CL register
  329.     xor    ch,ch            ; Convert string length into full word
  330.     mov    dx,si            ; Setup error string address
  331.     int    DOS            ; Print the error string to handle
  332.     Restore ds            ; Restore the required registers
  333.     ret                ; Return to the caller
  334. Error        Endp            ; End of the Error procedure
  335.     Subttl    Exit        Emulator Exit Routine
  336.     Page    +
  337. ;******************************************************************************
  338. ;
  339. ;    Exit()
  340. ;
  341. ;        Call routine to reset interrupt vectors
  342. ;        Call routine to reset video
  343. ;        Call routine to reset keyboard
  344. ;        Zero the return code
  345. ;        Exit to DOS
  346. ;
  347. ;    Registers on Entry:
  348. ;
  349. ;        None
  350. ;
  351. ;    Registers on Exit:
  352. ;
  353. ;        None
  354. ;
  355. ;******************************************************************************
  356.         Even            ; Force procedure to even address
  357. Exit        Proc    Near        ; Emulator exit procedure
  358.     call    Int_Reset        ; Call the interrupt reset routine
  359.     call    Video_Reset        ; Call the video reset routine
  360.     call    Key_Reset        ; Call the keyboard reset routine
  361.     mov    ah,TERMINATE        ; Get the terminate function code
  362.     xor    al,al            ; Zero the return code
  363.     int    DOS            ; Return control to MS-DOS
  364.     ret                ; Return to the caller (Never executed)
  365. Exit        Endp            ; End of the Exit procedure
  366.     Subttl    Read_Memory    Read 65C02 Apple Memory Routine
  367.     Page    +
  368. ;******************************************************************************
  369. ;
  370. ;    Read_Memory(Effective_Address)
  371. ;
  372. ;        Get the memory page from effective address
  373. ;        Jump to correct routine to process read
  374. ;
  375. ;    Registers on Entry:
  376. ;
  377. ;        DS:DI - 65C02 Effective address
  378. ;
  379. ;    Registers on Exit:
  380. ;
  381. ;        AL    - 65C02 Memory value
  382. ;        BP    - Destroyed
  383. ;
  384. ;******************************************************************************
  385.         Even            ; Force procedure to even address
  386. Read_Memory    Proc    Near        ; Read 65C02 Apple memory procedure
  387.     mov    bp,di            ; Get the effective address
  388.     shr    bp,8            ; Get page number into BP register
  389.     shl    bp,1            ; Convert page number to table index
  390.     jmp    cs:[bp + Read_Table]    ; Jump to correct routine to read
  391.     ret                ; Return to the caller (Never executed)
  392. Read_Memory    Endp            ; End of the Read_Memory procedure
  393.     Subttl    Write_Memory    Write 65C02 Apple Memory Routine
  394.     Page    +
  395. ;******************************************************************************
  396. ;
  397. ;    Write_Memory(Effective_Address, Data_Value)
  398. ;
  399. ;        Get the memory page from effective address
  400. ;        Jump to correct routine to process write
  401. ;
  402. ;    Registers on Entry:
  403. ;
  404. ;        DS:DI - 65C02 Effective address
  405. ;        AL    - 65C02 Memory value
  406. ;
  407. ;    Registers on Exit:
  408. ;
  409. ;        AX    - Destroyed
  410. ;        DI    - Destroyed
  411. ;        BP    - Destroyed
  412. ;
  413. ;******************************************************************************
  414.         Even            ; Force procedure to even address
  415. Write_Memory    Proc    Near        ; Write 65C02 Apple memory procedure
  416.     mov    bp,ax            ; Save memory value in BP register
  417.     mov    ax,di            ; Get the effective address
  418.     shr    ax,8            ; Get page number into AX register
  419.     shl    ax,1            ; Convert page number to table index
  420.     xchg    bp,ax            ; Setup to jump to correct routine
  421.     jmp    cs:[bp + Write_Table]    ; Jump to correct routine to write
  422.     ret                ; Return to the caller (Never executed)
  423. Write_Memory     Endp            ; End of the Write_Memory procedure
  424.     Subttl    System_Reset    Apple System Reset Routine
  425.     Page    +
  426. ;******************************************************************************
  427. ;
  428. ;    System_Reset(Scan_Code)
  429. ;
  430. ;        If the last scan code does NOT match (NOT a repeat)
  431. ;            If this is a make code
  432. ;                Set system reset interrupt type
  433. ;            Endif this is a break code
  434. ;        Endif this key is repeating
  435. ;        Return control to the caller
  436. ;
  437. ;    Registers on Entry:
  438. ;
  439. ;        None
  440. ;
  441. ;    Registers on Exit:
  442. ;
  443. ;        None
  444. ;
  445. ;******************************************************************************
  446.         Even            ; Force procedure to even address
  447. System_Reset    Proc    Near        ; Apple system reset procedure
  448.     cmp    ah,cs:[Last_Key]    ; Check for a repeat scan code
  449.     je    Reset_Done        ; Jump if this key is repeating
  450.     or    ah,ah            ; Check for a make or break code
  451.     js    Reset_Done        ; Jump if this is a break code
  452.     or    cs:[Emulate_Flag],SYS_RESET
  453. Reset_Done:
  454.     ret                ; Return to the caller
  455. System_Reset     Endp            ; End of the System_Reset procedure
  456.     Subttl    System_Request    Emulator System Request Routine
  457.     Page    +
  458. ;******************************************************************************
  459. ;
  460. ;    System_Request()
  461. ;
  462. ;        If this is a make code
  463. ;            Set system request interrupt type
  464. ;        Endif this is a break code
  465. ;        Return control to the caller
  466. ;
  467. ;    Registers on Entry:
  468. ;
  469. ;        None
  470. ;
  471. ;    Registers on Exit:
  472. ;
  473. ;        None
  474. ;
  475. ;******************************************************************************
  476.         Even            ; Force procedure to even address
  477. System_Request    Proc    Near        ; Emulator system request procedure
  478.     or    ah,ah            ; Check for a make or break code
  479.     js    Request_Done        ; Jump if this is a break code
  480.     test    cs:[Emulate_Flag],SYS_REQUEST
  481.     jnz    Request_Done        ; Jump if already in system procedure
  482.     or    cs:[Emulate_Flag],SYS_REQUEST
  483. Request_Done:
  484.     ret                ; Return to the caller
  485. System_Request     Endp            ; End of the System_Request procedure
  486.     Subttl    Reset_System    Reset System Routine
  487.     Page    +
  488. ;******************************************************************************
  489. ;
  490. ;    Reset_System(Interrupt_Number, RAM_Space, Registers, Address)
  491. ;
  492. ;        Clear the system reset interrupt bit
  493. ;        Call routine to reset the processor registers
  494. ;        Setup to execute the next opcode (No interrupt check)
  495. ;        Go process the next opcode
  496. ;
  497. ;    Registers on Entry:
  498. ;
  499. ;        DL    - 65C02 Accumulator
  500. ;        DH    - 65C02 processor flags
  501. ;        CL    - 65C02 Y index register
  502. ;        CH    - 65C02 X index register
  503. ;        BX    - 65C02 Stack pointer
  504. ;        SI    - 65C02 Program counter
  505. ;        AX    - Interrupt number (Doubled)
  506. ;        DI    - Current opcode address
  507. ;        DS    - 65C02 RAM space
  508. ;
  509. ;    Registers on Exit:
  510. ;
  511. ;        DL    - Accumulator initialized        (0h)
  512. ;        DH    - 65C02 flags initialized        (0h)
  513. ;        CL    - Y index register initialized   (0h)
  514. ;        CH    - X index register initialized   (0h)
  515. ;        BX    - Stack pointer initialized    (1FFh)
  516. ;        SI    - Program counter initialized (FFFCh)
  517. ;        DI    - Set to new opcode address
  518. ;
  519. ;******************************************************************************
  520.         Even            ; Force procedure to even address
  521. Reset_System    Proc    Near        ; Reset system procedure
  522.     and    cs:[Emulate_Flag],Not SYS_RESET
  523.     call    CPU_Init        ; Call routine to initialize registers
  524.     Setup                ; Setup the new opcode address
  525.     jmp    di            ; Go process the new opcode
  526. Reset_System    Endp            ; End of the Reset_System procedure
  527.     Subttl    Request_System    Request System Routine
  528.     Page    +
  529. ;******************************************************************************
  530. ;
  531. ;    Request_System(Interrupt_Number, RAM_Space, Registers, Address)
  532. ;
  533. ;
  534. ;
  535. ;    Registers on Entry:
  536. ;
  537. ;        DL    - 65C02 Accumulator
  538. ;        DH    - 65C02 processor flags
  539. ;        CL    - 65C02 Y index register
  540. ;        CH    - 65C02 X index register
  541. ;        BX    - 65C02 Stack pointer
  542. ;        SI    - 65C02 Program counter
  543. ;        AX    - Interrupt number (Doubled)
  544. ;        DI    - Current opcode address
  545. ;        DS    - 65C02 RAM space
  546. ;
  547. ;    Registers on Exit:
  548. ;
  549. ;        None
  550. ;
  551. ;******************************************************************************
  552.         Even            ; Force procedure to even address
  553. Request_System    Proc    Near        ; Request system procedure
  554.     or    cs:[System_Flag],INPUT    ; Put keyboard into input mode
  555.     call    Flush_Keyboard        ; Call routine to flush the keyboard
  556.     call    TTY_Init        ; Call routine to initialize TTY console
  557.     call    Clear_Screen        ; Call routine to clear the screen
  558. Request_Exit:
  559.     and    cs:[System_Flag],Not INPUT
  560.     and    cs:[Emulate_Flag],Not SYS_REQUEST
  561.     call    Exit            ; Call routine to exit the emulator
  562.     ret                ; Return control to the caller
  563. Request_System    Endp            ; End of the Request_System procedure
  564. ;******************************************************************************
  565. ;
  566. ;    Define the end of the Emulator Code Segment
  567. ;
  568. ;******************************************************************************
  569. Emulate Ends
  570.     End                ; End of the Apple module
  571.