[Coco] 6309 microprocessor project 01-14-2004
John Collyer
johncollyer at zoominternet.net
Wed Jan 14 12:16:22 EST 2004
6309 microprocessor project:
Hello,
Just to refresh everyone's memory; you'll remember that the
6309 Instruction Set Interpreter is completely 32 bit assembly
now and I only count 5 call instructions. Wow! That is optimized
as good as it gets, but if I macro the (General $FFxxH page I/O
function lookup) located in the Colour Computer Device Memory
Handler file I can get almost total optimization for this part of the
emulator.
Also, remember I said about the special opcodes $11FD and $11FF.
1.) Special Opcode $11FD:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;This special opcode is kernel win32 file functions. Enter with the (6309
REGX)
;pointing to the parameters. On return the (6309 REGQ) contains the result.
;
; The win32 functions for special opcode $11FD include:
;
; 1. CloseHandle
; 2. CopyFile
; 3. CreateDirectory
; 4. CreateFile
; 5. DeleteFile
; 6. FindClose
; 7. FindFirstFile
; 8. FindNextFile
; 9. FlushFileBuffers
; 10. GetCurrentDirectory
; 11. GetDiskFreeSpace
; 12. GetFileAttributes
; 13. GetFileSize
; 14. GetFileTime
; 15. GetFullPathName
; 16. GetLastError
; 17. GetLongPathName
; 18. GetShortPathName
; 19. GetTempFileName
; 20. GetTempPath
; 21. OpenFile
; 22. ReadFile
; 23. RemoveDirectory
; 24. SearchPath
; 25. SetCurrentDirectory
; 26. SetEndOfFile
; 27. SetFileAttributes
; 28. SetFilePointer
; 29. SetFileTime
; 30. WriteFile
;
; You interface with these functions by using opcode $11FD followed by a
; postbyte of the function call number (1 - 30) and register x pointing to
the
; parameter block (Register X contains the address of the first parameter of
; the parameters needed for the win32 function call).
;
; To set up the parameters look at the win32.api documentation and save any
; parameters in memory just as you see in the win32.api definition.
;
; Here is a example:
;
; BeginEx leax MyFile,pcr * the x register has to point to the
parameters
; jsr Mywin32_4 * call create file
; stq MyHandle * save file handle, 32-bits
; *
; * do something to the file
; *
; leax MyHandle,pcr * the x register has to point to the
parameters
; jsr Mywin32_1 * call close the file
; testf * If there are no errors, note since win32
returns BOOL (0/1)
; bne noerror *
; os9 F$Exit * Else exit with the error
; noerror os9 F$Exit * exit with no errors
; end BeginEx * done with example
;
; ***********************************************
; * HANDLE CreateFile(
; *
; * LPCTSTR lpFileName, // pointer to name of the file
; * DWORD dwDesiredAccess, // access (read-write) mode
; * DWORD dwShareMode, // share mode
; * LPSECURITY_ATTRIBUTES lpSecurityAttributes, // pointer to security
attributes
; * DWORD dwCreationDistribution, // how to create
; * DWORD dwFlagsAndAttributes, // file attributes
; * HANDLE hTemplateFile // handle to file with attributes to copy
; * );
; *
; *
; Mywin32_4 fcb $11,$FD,$04 * call CreateFile(...)
; rts *
;
; MyFile fcc "Filename" *
; fcb 0 * <- c strings
; dwDAccess fcb 0,0,0,0 *
; dwSMode fcb 0,0,0,0 *
; lpSAttr fdb Attrib * pointer to security attributes, 16-bit
address
; dwCreat fcb 0,0,0,0 *
; dwFlagA fcb 0,0,0,0 *
; hTmpFile fcb 0,0,0,0 *
; *
; Attrib fcb 0,0,0,0 * 32-bit security attributes
; *
; *****************************
; * BOOL CloseHandle(
; *
; * HANDLE hObject // handle to object to close
; * );
; *****************************
;
; Mywin32_1 fcb $11,$FD,$01 * call CloseHandle(MyHandle);
; rts * return
; MyHandle fcb 0,0,0,0 * win32 handles are 32 bits
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2.) Special Opcode $11FF:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;The enhanced instruction opcode $11FF will as before let you run code,
;but this code will be Intel 32 bit flat assembly code.
;
; You return to the emulator after your finished with the code by specifying
; a 80386 return instruction. The 80386 code should be located right after
; the enhanced instruction opcode $11FF in memory. All this can be
; accomplished because win32 lets us allocate memory designated as
; read/write/execute. If you are concerned about security you can set a
; switch not allowing enhanced opcodes.
;
; You interface with enhanced instruction opcode by using opcode $11FF
; and register x pointing to a memory block containing your 80386 virtual
; registers (Register X contains the address of the first virtual register
; in the memory block of your 80386 virtual registers). The virtual
; registers should be defined as follows and must be in this order in
; the memory block.
;
; The 80386 code should be placed right after the opcode $11FF in your
program as data.
; How you get the 80386 code into data and the correctness of that data
remains the
; programmers problem and the enhanced instruction opcode is only a
interface allowing
; you to execute the data that contains 80386 code. When you finish
executing the
; 80386 code use a "ret" instruction to return to your program. Note that
this means
; you must load the 80x86 register SI with your 6809 re-entry address before
issuing
; a "RET" instruction.
;
; Here is a example:
;
; BeginEx pshs u *
; leau v86_eax,pcr * Point to My virtual registers
; ldy #28 * sizeof virtual register data block
; ldq #$0FFFFFFFF * This is simulated register data
; storedata stq ,u * Save data in virtual registers block
; leau 4,u * Point to next virtual register in block
; leay -1,y * count it
; bne storedata * store all data
; leax v86_eax,pcr * Point to My virtual registers data block
; fdb $11FF * Call the win 32 code below
; *
; * My 32 bit code * esi points here = program counter
; *
; fcb $00,$00 * mov eax,0 ;simulate 32bit code
; fcb $83,$C6,06 * add esi,00000006 ;add size of this 32bit
; * ;code into esi = program
counter
; fcb $C3 * ret ;return
;
; * We returned from 32bit code here
;
; ldq v86_eax * Get virtual register eax
; tstw * Any return value?
; beq quit * No,
; exg w,d * Exchange words
; stq v86_eax * Save it
;
; quit os9 F$Exit * Done
;
; end BeginEx * done with example
;
; * My virtual 80386 registers
;
; v86_eax fcb 0,0,0,0 * 32 bit register
; v86_ebx fcb 0,0,0,0 * 32 bit register
; v86_ecx fcb 0,0,0,0 * 32 bit register
; v86_edx fcb 0,0,0,0 * 32 bit register
; v86_edi fcb 0,0,0,0 * 32 bit register
; v86_esi fcb 0,0,0,0 * 32 bit register
; v86_ebp fcb 0,0,0,0 * 32 bit register
;
; Notes:
;
; You must keep this order for the 80386 virtual registers and
; you must supply the data block of virtual 80386 registers with
; register "x" pointing to it to call the enhanced instruction
; opcode $11FF correctly. The enhanced opcode saves the 80386
; registers, after you return into the virtual 80386 register
; memory block you supplied with register "x" pointing to it,
; when you called the enhanced opcode $11FF. This interface to
; Intel assembly language is very limited and extreme caution
; should be used when using the interface, protection and
; runtime errors which occur will crash the emulator.
;
; The obvious reason for this is allowing you to manipulate
; data with native code to more easily control the interface
; with the kernel win32 functions.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
This part of the emulator is done; for anyone interested; the above
information
will be available in the first release of the emulator, whenever that
happens to be,
and you can consider the two interfaces above to be working correctly.
John Collyer
More information about the Coco
mailing list