Exemple #1
0
        /*
         * z_copy_table, copy a table or fill it with zeroes.
         *
         *	zargs[0] = address of table
         *  zargs[1] = destination address or 0 for fill
         *	zargs[2] = size of table
         *
         * Note: Copying is safe even when source and destination overlap; but
         *       if zargs[1] is negative the table _must_ be copied forwards.
         *
         */

        internal static void ZCopyTable()
        {
            zword addr;
            zword size = Process.zargs[2];
            zbyte value;
            int   i;

            if (Process.zargs[1] == 0)                                          /* zero table */
            {
                for (i = 0; i < size; i++)
                {
                    FastMem.StoreB((zword)(Process.zargs[0] + i), 0);
                }
            }
            else if ((short)size < 0 || Process.zargs[0] > Process.zargs[1])    /* copy forwards */
            {
                for (i = 0; i < (((short)size < 0) ? -(short)size : size); i++)
                {
                    addr = (zword)(Process.zargs[0] + i);
                    FastMem.LowByte(addr, out value);
                    FastMem.StoreB((zword)(Process.zargs[1] + i), value);
                }
            }
            else                                                                /* copy backwards */
            {
                for (i = size - 1; i >= 0; i--)
                {
                    addr = (zword)(Process.zargs[0] + i);
                    FastMem.LowByte(addr, out value);
                    FastMem.StoreB((zword)(Process.zargs[1] + i), value);
                }
            }
        } /* z_copy_table */
Exemple #2
0
        }/* memory_new_line */

        /*
         * memory_word
         *
         * Redirect a string of characters to the memory of the Z-machine.
         *
         */

        internal static void MemoryWord(ReadOnlySpan <zword> s)
        {
            zword addr;
            zword c;

            int pos = 0;

            if (Main.h_version == ZMachine.V6)
            {
                int width = OS.StringWidth(s);

                if (redirect[depth].XSize != 0xffff)
                {
                    if (redirect[depth].Width + width > redirect[depth].XSize)
                    {
                        if (s[pos] is ' ' or CharCodes.ZC_INDENT or CharCodes.ZC_GAP)
                        {
                            width = OS.StringWidth(s.Slice(++pos));
                        }

                        MemoryNewline();
                    }
                }

                redirect[depth].Width += (zword)width;
            }

            addr = redirect[depth].Table;

            FastMem.LowWord(addr, out zword size);
            addr += 2;

            while ((c = s[pos++]) != 0)
            {
                FastMem.StoreB((zword)(addr + (size++)), Text.TranslateToZscii(c));
            }

            FastMem.StoreW(redirect[depth].Table, size);
        }/* memory_word */
Exemple #3
0
        }/* memory_open */

        /*
         * memory_new_line
         *
         * Redirect a newline to the memory of the Z-machine.
         *
         */

        internal static void MemoryNewline()
        {
            zword addr;

            redirect[depth].Total += redirect[depth].Width;
            redirect[depth].Width  = 0;

            addr = redirect[depth].Table;

            FastMem.LowWord(addr, out zword size);
            addr += 2;

            if (redirect[depth].XSize != 0xffff)
            {
                redirect[depth].Table = (zword)(addr + size);
                size = 0;
            }
            else
            {
                FastMem.StoreB((zword)(addr + (size++)), 13);
            }

            FastMem.StoreW(redirect[depth].Table, size);
        }/* memory_new_line */
Exemple #4
0
        }/* z_scan_table */

        /*
         * z_storeb, write a byte into a table of bytes.
         *
         *	zargs[0] = address of table
         *	zargs[1] = index of table entry
         *	zargs[2] = value to be written
         *
         */

        internal static void ZStoreB()
        {
            FastMem.StoreB((zword)(Process.zargs[0] + Process.zargs[1]), (byte)Process.zargs[2]);
        } /* z_storeb */