[Coco] Re 6309 microprocessor project 01-22-2004

John Collyer johncollyer at zoominternet.net
Fri Jan 23 12:03:40 EST 2004


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
                              *
                              *
  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
                              *
  Mywin32_1 fcb $11,$FD,$01   * call CloseHandle(MyHandle);
            rts               * return
                              *
  MyHandle  fcb 0,0,0,0       * win32 handles are 32 bits
                              *
            end BeginEx       * done with example
                              *


Here is the special opcode $11FD code along with the two
win32 functions called from the example code above.


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                                        ;
yfd:    cmp word ptr native,564ah       ;If navtive instructions
        jnz yfd_off                     ;Else bad instruction
        test secur,-1                   ;If security = on
        jz yfd_off                      ;
        mov bx,si                       ;get program counter
        getbyte                         ;get the postbyte
        inc si                          ;increment program counter
        and eax,1eh                     ;only have 30 call codes
        jmp win[eax*4]                  ;jump to win32 function
yfd_off:                                ;Else bad instruction
        jmp bad                         ;and jump to bad instruction label.
                                        ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;The CloseHandle function closes an open object handle.
; BOOL CloseHandle(
;
;    HANDLE hObject  // handle to object to close
; );
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                                        ;
win01:  push esi                        ;save registers
        mov si,regx                     ;get parameters
        getptr                          ;
        mov esi,[eax]                   ;param 1 (handle to object to close)
        bswap esi                       ;make little endian
        invoke CloseHandle,esi          ;
        result                          ;save CloseHandle results
        pop esi                         ;restore registers
        ret                             ;return
                                        ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;The CreateFile function creates or opens the following objects
;and returns a handle that can be used to access the object:
;
;  · files
;  · pipes
;  · mailslots
;  · communications resources
;  · disk devices (Windows NT only)
;  · consoles
;  · directories (open only)
;
; 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
; );
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                                        ;
win04:  push esi                        ;Save registers
        push ebx                        ;
        mov si,regx                     ;Get parameters
        getptr                          ;make it 32-bit pointer
        mov ebx,eax                     ;save parameters
        mov si,[ebx]                    ;param 1 (pointer to name of the
file)
        getptr                          ;
        mov dd_aux1,eax                 ;
        mov eax,[ebx+2]                 ;param 2 (access read-write mode)
        bswap eax                       ;make little endian
        mov dd_aux2,eax                 ;
        mov eax,[ebx+6]                 ;param 3 (share mode)
        bswap eax                       ;make little endian
        mov dd_aux3,eax                 ;
        mov si,[ebx+10]                 ;param 4 (pointer to security
attributes)
        getptr                          ;
        mov dd_aux4,eax                 ;
        mov eax,[ebx+12]                ;param 5 (how to create)
        bswap eax                       ;make little endian
        mov dd_aux5,eax                 ;
        mov eax,[ebx+16]                ;param 6 (file attributes)
        bswap eax                       ;make little endian
        mov dd_aux6,eax                 ;
        mov eax,[ebx+20]                ;param 7 (handle to file with
attributes to copy)
        bswap eax                       ;make little endian
        invoke
CreateFile,dd_aux1,dd_aux2,dd_aux3,dd_aux4,dd_aux5,dd_aux6,eax
        result                          ;save CreateFile results
        pop ebx                         ;restore registers
        pop esi                         ;
        ret                             ;return
                                        ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;




More information about the Coco mailing list